This commit is contained in:
Liang Ding 2022-06-15 23:56:47 +08:00
parent 4170f50dc6
commit 102d9364fd
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
25 changed files with 118 additions and 398 deletions

View file

@ -35,7 +35,7 @@ import (
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/gabriel-vasile/mimetype"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
@ -671,7 +671,7 @@ func copyDocAssetsToDataAssets(boxID, parentDocPath string) {
}
func copyAssetsToDataAssets(rootPath string) {
filesys.ReleaseFileLocks(rootPath)
filelock.ReleaseFileLocks(rootPath)
var assetsDirPaths []string
filepath.Walk(rootPath, func(path string, info fs.FileInfo, err error) error {

View file

@ -33,7 +33,7 @@ import (
"github.com/88250/gulu"
"github.com/dustin/go-humanize"
"github.com/siyuan-note/encryption"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -145,7 +145,10 @@ func RecoverLocalBackup() (err error) {
writingDataLock.Lock()
defer writingDataLock.Unlock()
filesys.ReleaseAllFileLocks()
err = filelock.ReleaseAllFileLocks()
if nil != err {
return
}
sql.WaitForWritingDatabase()
CloseWatchAssets()
@ -256,7 +259,10 @@ func CreateLocalBackup() (err error) {
defer writingDataLock.Unlock()
WaitForWritingFiles()
sql.WaitForWritingDatabase()
filesys.ReleaseAllFileLocks()
err = filelock.ReleaseAllFileLocks()
if nil != err {
return
}
util.LogInfof("creating backup...")
start := time.Now()

View file

@ -32,8 +32,8 @@ import (
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/facette/natsort"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/conf"
"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"
@ -85,14 +85,14 @@ func ListNotebooks() (ret []*Box, err error) {
boxConfPath := filepath.Join(util.DataDir, dir.Name(), ".siyuan", "conf.json")
if !gulu.File.IsExist(boxConfPath) {
if isUserGuide(dir.Name()) {
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
os.RemoveAll(filepath.Join(util.DataDir, dir.Name()))
util.LogWarnf("not found user guid box conf [%s], removed it", boxConfPath)
continue
}
util.LogWarnf("not found box conf [%s], recreate it", boxConfPath)
} else {
data, readErr := filesys.NoLockFileRead(boxConfPath)
data, readErr := filelock.NoLockFileRead(boxConfPath)
if nil != readErr {
util.LogErrorf("read box conf [%s] failed: %s", boxConfPath, readErr)
continue
@ -152,7 +152,7 @@ func (box *Box) GetConf() (ret *conf.BoxConf) {
return
}
data, err := filesys.LockFileRead(confPath)
data, err := filelock.LockFileRead(confPath)
if nil != err {
util.LogErrorf("read box conf [%s] failed: %s", confPath, err)
return
@ -173,7 +173,7 @@ func (box *Box) SaveConf(conf *conf.BoxConf) {
return
}
oldData, err := filesys.NoLockFileRead(confPath)
oldData, err := filelock.NoLockFileRead(confPath)
if nil != err {
box.saveConf0(newData)
return
@ -191,7 +191,7 @@ func (box *Box) saveConf0(data []byte) {
if err := os.MkdirAll(filepath.Join(util.DataDir, box.ID, ".siyuan"), 0755); nil != err {
util.LogErrorf("save box conf [%s] failed: %s", confPath, err)
}
if err := filesys.LockFileWrite(confPath, data); nil != err {
if err := filelock.LockFileWrite(confPath, data); nil != err {
util.LogErrorf("save box conf [%s] failed: %s", confPath, err)
}
}
@ -279,7 +279,7 @@ func (box *Box) Move(oldPath, newPath string) error {
boxLocalPath := filepath.Join(util.DataDir, box.ID)
fromPath := filepath.Join(boxLocalPath, oldPath)
toPath := filepath.Join(boxLocalPath, newPath)
filesys.ReleaseFileLocks(fromPath)
filelock.ReleaseFileLocks(fromPath)
if err := os.Rename(fromPath, toPath); nil != err {
msg := fmt.Sprintf(Conf.Language(5), box.Name, fromPath, err)
util.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, box.Name, err)
@ -299,7 +299,7 @@ func (box *Box) Move(oldPath, newPath string) error {
func (box *Box) Remove(path string) error {
boxLocalPath := filepath.Join(util.DataDir, box.ID)
filePath := filepath.Join(boxLocalPath, path)
filesys.ReleaseFileLocks(filePath)
filelock.ReleaseFileLocks(filePath)
if err := os.RemoveAll(filePath); nil != err {
msg := fmt.Sprintf(Conf.Language(7), box.Name, path, err)
util.LogErrorf("remove [path=%s] in box [%s] failed: %s", path, box.ID, err)
@ -317,7 +317,7 @@ func (box *Box) Unindex() {
sql.RemoveBoxHash(tx, box.ID)
sql.DeleteByBoxTx(tx, box.ID)
sql.CommitTx(tx)
filesys.ReleaseFileLocks(filepath.Join(util.DataDir, box.ID))
filelock.ReleaseFileLocks(filepath.Join(util.DataDir, box.ID))
treenode.RemoveBlockTreesByBoxID(box.ID)
}
@ -528,5 +528,5 @@ func LockFileByBlockID(id string) (locked bool, filePath string) {
if !gulu.File.IsExist(p) {
return true, ""
}
return nil == filesys.LockFile(p), p
return nil == filelock.LockFile(p), p
}

View file

@ -34,8 +34,8 @@ import (
"github.com/88250/lute"
humanize "github.com/dustin/go-humanize"
"github.com/getsentry/sentry-go"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/conf"
"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"
@ -386,7 +386,7 @@ func (conf *AppConf) Save() {
newData, _ := gulu.JSON.MarshalIndentJSON(Conf, "", " ")
confPath := filepath.Join(util.ConfDir, "conf.json")
oldData, err := filesys.NoLockFileRead(confPath)
oldData, err := filelock.NoLockFileRead(confPath)
if nil != err {
conf.save0(newData)
return
@ -401,7 +401,7 @@ func (conf *AppConf) Save() {
func (conf *AppConf) save0(data []byte) {
confPath := filepath.Join(util.ConfDir, "conf.json")
if err := filesys.LockFileWrite(confPath, data); nil != err {
if err := filelock.LockFileWrite(confPath, data); nil != err {
util.LogFatalf("write conf [%s] failed: %s", confPath, err)
}
}

View file

@ -40,7 +40,7 @@ import (
"github.com/88250/pdfcpu/pkg/pdfcpu"
"github.com/emirpasic/gods/sets/hashset"
"github.com/emirpasic/gods/stacks/linkedliststack"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@ -112,7 +112,10 @@ func exportData(exportFolder string) (err error) {
return
}
filesys.ReleaseAllFileLocks()
err = filelock.ReleaseAllFileLocks()
if nil != err {
return
}
data := filepath.Join(util.WorkspaceDir, "data")
if err = stableCopy(data, exportFolder); nil != err {
@ -659,7 +662,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
// 按文件夹结构复制选择的树
for _, tree := range trees {
readPath := filepath.Join(util.DataDir, tree.Box, tree.Path)
data, readErr := filesys.NoLockFileRead(readPath)
data, readErr := filelock.NoLockFileRead(readPath)
if nil != readErr {
util.LogErrorf("read file [%s] failed: %s", readPath, readErr)
continue
@ -681,7 +684,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
// 引用树放在导出文件夹根路径下
for treeID, tree := range refTrees {
readPath := filepath.Join(util.DataDir, tree.Box, tree.Path)
data, readErr := filesys.NoLockFileRead(readPath)
data, readErr := filelock.NoLockFileRead(readPath)
if nil != readErr {
util.LogErrorf("read file [%s] failed: %s", readPath, readErr)
continue

View file

@ -39,6 +39,7 @@ import (
"github.com/dustin/go-humanize"
"github.com/facette/natsort"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/search"
@ -133,9 +134,9 @@ func (box *Box) docIAL(p string) (ret map[string]string) {
filePath := filepath.Join(util.DataDir, box.ID, p)
data, err := filesys.NoLockFileRead(filePath)
data, err := filelock.NoLockFileRead(filePath)
if util.IsCorruptedSYData(data) {
filesys.UnlockFile(filePath)
filelock.UnlockFile(filePath)
if removeErr := os.RemoveAll(filePath); nil == removeErr {
util.LogInfof("removed corrupted data file [path=%s, length=%d]", filePath, len(data))
} else {
@ -1043,9 +1044,9 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
} else {
absFromPath := filepath.Join(util.DataDir, fromBoxID, fromFolder)
absToPath := filepath.Join(util.DataDir, toBoxID, newFolder)
filesys.ReleaseFileLocks(absFromPath)
filelock.ReleaseFileLocks(absFromPath)
if gulu.File.IsExist(absToPath) {
filesys.ReleaseFileLocks(absToPath)
filelock.ReleaseFileLocks(absToPath)
os.RemoveAll(absToPath)
}
if err = os.Rename(absFromPath, absToPath); nil != err {
@ -1073,7 +1074,7 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
} else {
absFromPath := filepath.Join(util.DataDir, fromBoxID, fromPath)
absToPath := filepath.Join(util.DataDir, toBoxID, newPath)
filesys.ReleaseFileLocks(absFromPath)
filelock.ReleaseFileLocks(absFromPath)
if err = os.Rename(absFromPath, absToPath); nil != err {
msg := fmt.Sprintf(Conf.Language(5), fromBox.Name, fromPath, err)
util.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, fromBoxID, err)
@ -1118,7 +1119,7 @@ func RemoveDoc(boxID, p string) (err error) {
historyPath := filepath.Join(historyDir, boxID, p)
absPath := filepath.Join(util.DataDir, boxID, p)
filesys.ReleaseFileLocks(absPath)
filelock.ReleaseFileLocks(absPath)
if err = gulu.File.Copy(absPath, historyPath); nil != err {
return errors.New(fmt.Sprintf(Conf.Language(70), box.Name, absPath, err))
}
@ -1375,7 +1376,7 @@ func moveSorts(rootID, fromBox, toBox string) {
fromConfPath := filepath.Join(util.DataDir, fromBox, ".siyuan", "sort.json")
fromFullSortIDs := map[string]int{}
if gulu.File.IsExist(fromConfPath) {
data, err := filesys.LockFileRead(fromConfPath)
data, err := filelock.LockFileRead(fromConfPath)
if nil != err {
util.LogErrorf("read sort conf failed: %s", err)
return
@ -1392,7 +1393,7 @@ func moveSorts(rootID, fromBox, toBox string) {
toConfPath := filepath.Join(util.DataDir, toBox, ".siyuan", "sort.json")
toFullSortIDs := map[string]int{}
if gulu.File.IsExist(toConfPath) {
data, err := filesys.LockFileRead(toConfPath)
data, err := filelock.LockFileRead(toConfPath)
if nil != err {
util.LogErrorf("read sort conf failed: %s", err)
return
@ -1413,7 +1414,7 @@ func moveSorts(rootID, fromBox, toBox string) {
util.LogErrorf("marshal sort conf failed: %s", err)
return
}
if err = filesys.LockFileWrite(toConfPath, data); nil != err {
if err = filelock.LockFileWrite(toConfPath, data); nil != err {
util.LogErrorf("write sort conf failed: %s", err)
return
}
@ -1490,7 +1491,7 @@ func ChangeFileTreeSort(boxID string, paths []string) {
fullSortIDs := map[string]int{}
var data []byte
if gulu.File.IsExist(confPath) {
data, err = filesys.LockFileRead(confPath)
data, err = filelock.LockFileRead(confPath)
if nil != err {
util.LogErrorf("read sort conf failed: %s", err)
return
@ -1510,7 +1511,7 @@ func ChangeFileTreeSort(boxID string, paths []string) {
util.LogErrorf("marshal sort conf failed: %s", err)
return
}
if err = filesys.LockFileWrite(confPath, data); nil != err {
if err = filelock.LockFileWrite(confPath, data); nil != err {
util.LogErrorf("write sort conf failed: %s", err)
return
}
@ -1524,7 +1525,7 @@ func (box *Box) fillSort(files *[]*File) {
return
}
data, err := filesys.LockFileRead(confPath)
data, err := filelock.LockFileRead(confPath)
if nil != err {
util.LogErrorf("read sort conf failed: %s", err)
return
@ -1571,7 +1572,7 @@ func (box *Box) removeSort(rootID, path string) {
return
}
data, err := filesys.LockFileRead(confPath)
data, err := filelock.LockFileRead(confPath)
if nil != err {
util.LogErrorf("read sort conf failed: %s", err)
return
@ -1592,7 +1593,7 @@ func (box *Box) removeSort(rootID, path string) {
util.LogErrorf("marshal sort conf failed: %s", err)
return
}
if err = filesys.LockFileWrite(confPath, data); nil != err {
if err = filelock.LockFileWrite(confPath, data); nil != err {
util.LogErrorf("write sort conf failed: %s", err)
return
}
@ -1601,8 +1602,8 @@ func (box *Box) removeSort(rootID, path string) {
func ServeFile(c *gin.Context, filePath string) (err error) {
WaitForWritingFiles()
if filesys.IsLocked(filePath) {
if err = filesys.UnlockFile(filePath); nil == err {
if filelock.IsLocked(filePath) {
if err = filelock.UnlockFile(filePath); nil == err {
util.LogInfof("unlocked file [%s]", filePath)
} else {
msg := fmt.Sprintf("unlock file [%s] failed: %s", filePath, err)

View file

@ -25,7 +25,7 @@ import (
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -102,7 +102,7 @@ func generateFormatHistory(tree *parse.Tree) {
}
var data []byte
if data, err = filesys.NoLockFileRead(filepath.Join(util.DataDir, tree.Box, tree.Path)); err != nil {
if data, err = filelock.NoLockFileRead(filepath.Join(util.DataDir, tree.Box, tree.Path)); err != nil {
util.LogErrorf("generate history failed: %s", err)
return
}

View file

@ -28,8 +28,8 @@ import (
"github.com/88250/gulu"
"github.com/88250/protyle"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -133,7 +133,7 @@ func GetDocHistoryContent(historyPath string) (content string, err error) {
return
}
data, err := filesys.NoLockFileRead(historyPath)
data, err := filelock.NoLockFileRead(historyPath)
if nil != err {
util.LogErrorf("read file [%s] failed: %s", historyPath, err)
return
@ -162,7 +162,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
baseName := filepath.Base(historyPath)
id := strings.TrimSuffix(baseName, ".sy")
filesys.ReleaseFileLocks(filepath.Join(util.DataDir, boxID))
filelock.ReleaseFileLocks(filepath.Join(util.DataDir, boxID))
workingDoc := treenode.GetBlockTree(id)
if nil != workingDoc {
if err = os.RemoveAll(filepath.Join(util.DataDir, boxID, workingDoc.Path)); nil != err {
@ -285,7 +285,7 @@ func GetDocHistory(boxID string) (ret []*History, err error) {
return nil
}
data, err := filesys.NoLockFileRead(path)
data, err := filelock.NoLockFileRead(path)
if nil != err {
util.LogErrorf("read file [%s] failed: %s", path, err)
return nil
@ -489,7 +489,7 @@ func (box *Box) generateDocHistory0() {
}
var data []byte
if data, err = filesys.NoLockFileRead(file); err != nil {
if data, err = filelock.NoLockFileRead(file); err != nil {
util.LogErrorf("generate history failed: %s", err)
return
}

View file

@ -39,6 +39,7 @@ import (
"github.com/88250/lute/parse"
"github.com/88250/protyle"
"github.com/mattn/go-zglob"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
@ -253,7 +254,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
writingDataLock.Lock()
defer writingDataLock.Unlock()
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
var baseTargetPath string
if "/" == toPath {
@ -330,7 +331,7 @@ func ImportData(zipPath string) (err error) {
writingDataLock.Lock()
defer writingDataLock.Unlock()
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
tmpDataPath := filepath.Dir(filepath.Dir(confPath))
if err = stableCopy(tmpDataPath, util.DataDir); nil != err {
util.LogErrorf("copy data dir from [%s] to [%s] failed: %s", tmpDataPath, util.DataDir, err)

View file

@ -31,6 +31,7 @@ import (
"github.com/88250/lute/parse"
"github.com/dustin/go-humanize"
"github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql"
@ -69,7 +70,7 @@ func (box *Box) BootIndex() {
// 缓存块树
treenode.IndexBlockTree(tree)
if 1 < i && 0 == i%64 {
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
}
i++
}
@ -130,7 +131,7 @@ func (box *Box) Index(fullRebuildIndex bool) (treeCount int, treeSize int64) {
idHashMap[tree.ID] = tree.Hash
if 1 < i && 0 == i%64 {
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(88), i, len(files)-i))
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
}
i++
}
@ -210,7 +211,7 @@ func (box *Box) Index(fullRebuildIndex bool) (treeCount int, treeSize int64) {
}
if 1 < i && 0 == i%64 {
util.PushEndlessProgress(fmt.Sprintf("["+box.Name+"] "+Conf.Language(53), i, treeCount-i))
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
}
i++
}
@ -348,7 +349,7 @@ func IndexRefs() {
}
if 1 < i && 0 == i%64 {
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(55), i))
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
}
i++
}

View file

@ -27,7 +27,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -87,7 +87,7 @@ func RemoveBox(boxID string) (err error) {
return errors.New(fmt.Sprintf("can not remove [%s] caused by it is not a dir", boxID))
}
filesys.ReleaseFileLocks(localPath)
filelock.ReleaseFileLocks(localPath)
if !isUserGuide(boxID) {
var historyDir string
historyDir, err = util.GetHistoryDir("delete")

View file

@ -27,7 +27,7 @@ import (
"github.com/siyuan-note/dejavu"
"github.com/siyuan-note/dejavu/entity"
"github.com/siyuan-note/encryption"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -136,7 +136,7 @@ func CheckoutRepo(id string) (err error) {
defer writingDataLock.Unlock()
WaitForWritingFiles()
sql.WaitForWritingDatabase()
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
CloseWatchAssets()
defer WatchAssets()
@ -196,7 +196,7 @@ func IndexRepo(memo string) (err error) {
defer writingDataLock.Unlock()
WaitForWritingFiles()
sql.WaitForWritingDatabase()
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
_, err = repo.Index(memo, util.PushEndlessProgress, indexCallbacks)
util.PushClearProgress()

View file

@ -37,6 +37,7 @@ import (
"github.com/emirpasic/gods/sets/hashset"
"github.com/mattn/go-zglob"
"github.com/siyuan-note/encryption"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql"
@ -584,7 +585,7 @@ func syncDir2WorkspaceData(boot bool) (upsertFiles, removeFiles []string, err er
// 2. 将 data 中新增/修改的文件加密后拷贝到 sync 中
func workspaceData2SyncDir() (removeList, upsertList map[string]bool, err error) {
start := time.Now()
filesys.ReleaseAllFileLocks()
filelock.ReleaseAllFileLocks()
passwd := Conf.E2EEPasswd
unchangedDataList, removeList, err := calcUnchangedDataList(passwd)
@ -820,7 +821,7 @@ func prepareSyncData(passwd string, unchangedDataList map[string]bool) (encrypte
return io.EOF
}
data, err0 := filesys.NoLockFileRead(path)
data, err0 := filelock.NoLockFileRead(path)
if nil != err0 {
util.LogErrorf("read file [%s] failed: %s", path, err0)
err = err0
@ -1204,7 +1205,7 @@ func genSyncHistory(now, p string) {
relativePath := strings.TrimPrefix(p, util.DataDir)
historyPath := filepath.Join(historyDir, relativePath)
filesys.ReleaseFileLocks(p)
filelock.ReleaseFileLocks(p)
if err = gulu.File.Copy(p, historyPath); nil != err {
util.LogErrorf("gen sync history failed: %s", err)
return

View file

@ -32,8 +32,8 @@ import (
"github.com/88250/lute/parse"
util2 "github.com/88250/lute/util"
"github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/cache"
"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"
@ -434,7 +434,7 @@ func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) {
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID}
}
tree, err := tx.loadTree(block.ID)
if filesys.ErrUnableLockFile == err {
if errors.Is(err, filelock.ErrUnableLockFile) {
return &TxErr{code: TxErrCodeUnableLockFile, msg: err.Error(), id: block.ID}
}
if nil != err {
@ -522,7 +522,7 @@ func (tx *Transaction) doAppendInsert(operation *Operation) (ret *TxErr) {
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID}
}
tree, err := tx.loadTree(block.ID)
if filesys.ErrUnableLockFile == err {
if errors.Is(err, filelock.ErrUnableLockFile) {
return &TxErr{code: TxErrCodeUnableLockFile, msg: err.Error(), id: block.ID}
}
if nil != err {
@ -723,7 +723,7 @@ func (tx *Transaction) doLargeInsert() (ret *TxErr) {
}
id := parentBlock.ID
tree, err := tx.loadTree(id)
if filesys.ErrUnableLockFile == err {
if errors.Is(err, filelock.ErrUnableLockFile) {
return &TxErr{code: TxErrCodeUnableLockFile, msg: err.Error(), id: id}
}
if nil != err {
@ -784,7 +784,7 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
var err error
id := operation.ID
tree, err := tx.loadTree(id)
if filesys.ErrUnableLockFile == err {
if errors.Is(err, filelock.ErrUnableLockFile) {
return &TxErr{code: TxErrCodeUnableLockFile, msg: err.Error(), id: id}
}
if ErrBlockNotFound == err {
@ -835,7 +835,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
}
}
tree, err := tx.loadTree(block.ID)
if filesys.ErrUnableLockFile == err {
if errors.Is(err, filelock.ErrUnableLockFile) {
return &TxErr{code: TxErrCodeUnableLockFile, msg: err.Error(), id: block.ID}
}
if nil != err {
@ -969,7 +969,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
id := operation.ID
tree, err := tx.loadTree(id)
if filesys.ErrUnableLockFile == err {
if errors.Is(err, filelock.ErrUnableLockFile) {
return &TxErr{code: TxErrCodeUnableLockFile, msg: err.Error(), id: id}
}
if nil != err {

View file

@ -24,6 +24,7 @@ import (
"github.com/88250/lute/parse"
"github.com/88250/protyle"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@ -40,7 +41,7 @@ func loadTrees(localPath string) (ret []*parse.Tree) {
return nil
}
data, err := filesys.NoLockFileRead(path)
data, err := filelock.NoLockFileRead(path)
if nil != err {
util.LogErrorf("get data [path=%s] failed: %s", path, err)
return nil