mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
:file: 移除文件锁 https://github.com/siyuan-note/siyuan/issues/6010
This commit is contained in:
parent
56129699b9
commit
69a9713776
38 changed files with 193 additions and 438 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue