From d8fb5f896e2ebf7ad8161021a3e2c855fa628b4d Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 19 Dec 2023 20:03:13 +0800 Subject: [PATCH] :art: Improve kernel stability https://github.com/siyuan-note/siyuan/issues/9912 --- kernel/model/mount.go | 12 ++++++++++-- kernel/model/transaction.go | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/kernel/model/mount.go b/kernel/model/mount.go index 37616a099..04fabe4df 100644 --- a/kernel/model/mount.go +++ b/kernel/model/mount.go @@ -41,6 +41,11 @@ func CreateBox(name string) (id string, err error) { return } + WaitForWritingFiles() + + createDocLock.Lock() + defer createDocLock.Unlock() + id = ast.NewNodeID() boxLocalPath := filepath.Join(util.DataDir, id) err = os.MkdirAll(boxLocalPath, 0755) @@ -71,12 +76,15 @@ func RenameBox(boxID, name string) (err error) { } func RemoveBox(boxID string) (err error) { - WaitForWritingFiles() - if util.IsReservedFilename(boxID) { return errors.New(fmt.Sprintf("can not remove [%s] caused by it is a reserved file", boxID)) } + WaitForWritingFiles() + + createDocLock.Lock() + defer createDocLock.Unlock() + localPath := filepath.Join(util.DataDir, boxID) if !filelock.IsExist(localPath) { return diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 6bc09252d..73608c33d 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -87,7 +87,7 @@ var ( ) func isWritingFiles() bool { - time.Sleep(time.Duration(20) * time.Millisecond) + time.Sleep(time.Duration(50) * time.Millisecond) return 0 < len(txQueue) }