🎨 笔记本配置文件缺失时将笔记本文件夹移动到 工作空间/corrupted/ 文件夹下 Fix https://github.com/siyuan-note/siyuan/issues/5853

This commit is contained in:
Liang Ding 2022-09-09 16:28:42 +08:00
parent dc70850582
commit 38c70f13a4
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -83,15 +83,25 @@ func ListNotebooks() (ret []*Box, err error) {
}
boxConf := conf.NewBoxConf()
boxConfPath := filepath.Join(util.DataDir, dir.Name(), ".siyuan", "conf.json")
boxDirPath := filepath.Join(util.DataDir, dir.Name())
boxConfPath := filepath.Join(boxDirPath, ".siyuan", "conf.json")
if !gulu.File.IsExist(boxConfPath) {
filelock.ReleaseAllFileLocks()
if IsUserGuide(dir.Name()) {
filelock.ReleaseAllFileLocks()
os.RemoveAll(filepath.Join(util.DataDir, dir.Name()))
logging.LogWarnf("not found user guid box conf [%s], removed it", boxConfPath)
os.RemoveAll(boxDirPath)
continue
}
logging.LogWarnf("not found box conf [%s], recreate it", boxConfPath)
to := filepath.Join(util.WorkspaceDir, "corrupted", time.Now().Format("2006-01-02-150405"), dir.Name())
if renameErr := gulu.File.CopyDir(boxDirPath, to); nil != renameErr {
logging.LogErrorf("copy corrupted box [%s] failed: %s", boxDirPath, renameErr)
continue
}
if removeErr := os.RemoveAll(boxDirPath); nil != removeErr {
logging.LogErrorf("remove corrupted box [%s] failed: %s", boxDirPath, removeErr)
continue
}
logging.LogWarnf("moved corrupted box [%s] to [%s]", boxDirPath, to)
continue
} else {
data, readErr := filelock.NoLockFileRead(boxConfPath)
if nil != readErr {