This commit is contained in:
Liang Ding 2022-09-29 21:52:01 +08:00
parent 56129699b9
commit 69a9713776
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
38 changed files with 193 additions and 438 deletions

View file

@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
@ -32,7 +31,6 @@ import (
"github.com/dustin/go-humanize"
"github.com/siyuan-note/dejavu"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@ -64,9 +62,6 @@ func SyncData(boot, exit, byHand bool) {
return
}
filesys.LockWriteFile()
defer filesys.UnlockWriteFile()
if util.IsMutexLocked(&syncLock) {
logging.LogWarnf("sync is in progress")
planSyncAfter(30 * time.Second)
@ -411,38 +406,6 @@ func IncSync() {
planSyncAfter(30 * time.Second)
}
func stableCopy(src, dest string) (err error) {
if gulu.OS.IsWindows() {
robocopy := "robocopy"
cmd := exec.Command(robocopy, src, dest, "/DCOPY:T", "/E", "/IS", "/R:0", "/NFL", "/NDL", "/NJH", "/NJS", "/NP", "/NS", "/NC")
util.CmdAttr(cmd)
var output []byte
output, err = cmd.CombinedOutput()
if strings.Contains(err.Error(), "exit status 16") {
// 某些版本的 Windows 无法同步 https://github.com/siyuan-note/siyuan/issues/4197
return gulu.File.Copy(src, dest)
}
if nil != err && strings.Contains(err.Error(), exec.ErrNotFound.Error()) {
robocopy = os.Getenv("SystemRoot") + "\\System32\\" + "robocopy"
cmd = exec.Command(robocopy, src, dest, "/DCOPY:T", "/E", "/IS", "/R:0", "/NFL", "/NDL", "/NJH", "/NJS", "/NP", "/NS", "/NC")
util.CmdAttr(cmd)
output, err = cmd.CombinedOutput()
}
if nil == err ||
strings.Contains(err.Error(), "exit status 3") ||
strings.Contains(err.Error(), "exit status 1") ||
strings.Contains(err.Error(), "exit status 2") ||
strings.Contains(err.Error(), "exit status 5") ||
strings.Contains(err.Error(), "exit status 6") ||
strings.Contains(err.Error(), "exit status 7") {
return nil
}
logging.LogErrorf("robocopy data from [%s] to [%s] failed: %s %s", src, dest, string(output), err)
}
return gulu.File.Copy(src, dest)
}
func planSyncAfter(d time.Duration) {
syncPlanTime = time.Now().Add(d)
}