Browse Source

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

Liang Ding 2 years ago
parent
commit
38c70f13a4
1 changed files with 15 additions and 5 deletions
  1. 15 5
      kernel/model/box.go

+ 15 - 5
kernel/model/box.go

@@ -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 {