From 38c70f13a4f3ec98da108421a13a5fcb0f1c6313 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 9 Sep 2022 16:28:42 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E7=AC=94=E8=AE=B0=E6=9C=AC=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E7=BC=BA=E5=A4=B1=E6=97=B6=E5=B0=86?= =?UTF-8?q?=E7=AC=94=E8=AE=B0=E6=9C=AC=E6=96=87=E4=BB=B6=E5=A4=B9=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E5=88=B0=20`=E5=B7=A5=E4=BD=9C=E7=A9=BA=E9=97=B4/corr?= =?UTF-8?q?upted/`=20=E6=96=87=E4=BB=B6=E5=A4=B9=E4=B8=8B=20Fix=20https://?= =?UTF-8?q?github.com/siyuan-note/siyuan/issues/5853?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/box.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/kernel/model/box.go b/kernel/model/box.go index 7b1ee0b44..fab24fdff 100644 --- a/kernel/model/box.go +++ b/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 {