diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index bac16c6cc..fb92337f5 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -432,6 +432,7 @@ func createDoc(c *gin.Context) { return } + model.WaitForWritingFiles() box := model.Conf.Box(notebook) pushCreate(box, p, tree.Root.ID, arg) @@ -461,8 +462,8 @@ func createDailyNote(c *gin.Context) { return } - box := model.Conf.Box(notebook) model.WaitForWritingFiles() + box := model.Conf.Box(notebook) luteEngine := util.NewLute() tree, err := filesys.LoadTree(box.ID, p, luteEngine) if nil != err { @@ -549,6 +550,7 @@ func createDocWithMd(c *gin.Context) { } ret.Data = id + model.WaitForWritingFiles() box := model.Conf.Box(notebook) b, _ := model.GetBlock(id, nil) p := b.Path diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index ae5241ad9..5cced0a87 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -1694,6 +1694,8 @@ func replaceAttributeViewBlock(operation *Operation, tx *Transaction) (err error return } + WaitForWritingFiles() + var node *ast.Node if !operation.IsDetached { node, _, _ = getNodeByBlockID(tx, operation.NextID) @@ -1919,7 +1921,6 @@ func getNodeByBlockID(tx *Transaction, blockID string) (node *ast.Node, tree *pa tree, err = loadTreeByBlockID(blockID) } if nil != err { - logging.LogWarnf("load tree by block id [%s] failed: %s", blockID, err) return } node = treenode.GetNodeInTree(tree, blockID) diff --git a/kernel/model/file.go b/kernel/model/file.go index c9b4153ce..7b63db4a6 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1015,6 +1015,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Tree return } + WaitForWritingFiles() ChangeFileTreeSort(box.ID, sorts) return } @@ -1033,6 +1034,7 @@ func CreateWithMarkdown(boxID, hPath, md, parentID, id string) (retID string, er luteEngine := util.NewLute() dom := luteEngine.Md2BlockDOM(md, false) retID, err = createDocsByHPath(box.ID, hPath, dom, parentID, id) + WaitForWritingFiles() return } 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) }