mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🎨 改进已经损坏的数据处理 Fix https://github.com/siyuan-note/siyuan/issues/5853
This commit is contained in:
parent
38c70f13a4
commit
8f3dd9fbf4
2 changed files with 25 additions and 9 deletions
|
|
@ -92,8 +92,8 @@ func ListNotebooks() (ret []*Box, err error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
to := filepath.Join(util.WorkspaceDir, "corrupted", time.Now().Format("2006-01-02-150405"), dir.Name())
|
to := filepath.Join(util.WorkspaceDir, "corrupted", time.Now().Format("2006-01-02-150405"), dir.Name())
|
||||||
if renameErr := gulu.File.CopyDir(boxDirPath, to); nil != renameErr {
|
if copyErr := gulu.File.CopyDir(boxDirPath, to); nil != copyErr {
|
||||||
logging.LogErrorf("copy corrupted box [%s] failed: %s", boxDirPath, renameErr)
|
logging.LogErrorf("copy corrupted box [%s] failed: %s", boxDirPath, copyErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if removeErr := os.RemoveAll(boxDirPath); nil != removeErr {
|
if removeErr := os.RemoveAll(boxDirPath); nil != removeErr {
|
||||||
|
|
|
||||||
|
|
@ -137,12 +137,7 @@ func (box *Box) docIAL(p string) (ret map[string]string) {
|
||||||
|
|
||||||
data, err := filelock.NoLockFileRead(filePath)
|
data, err := filelock.NoLockFileRead(filePath)
|
||||||
if util.IsCorruptedSYData(data) {
|
if util.IsCorruptedSYData(data) {
|
||||||
filelock.UnlockFile(filePath)
|
box.moveCorruptedData(filePath)
|
||||||
if removeErr := os.RemoveAll(filePath); nil == removeErr {
|
|
||||||
logging.LogInfof("removed corrupted data file [path=%s, length=%d]", filePath, len(data))
|
|
||||||
} else {
|
|
||||||
logging.LogWarnf("remove corrupted data file [path=%s, length=%d] failed: %s", filePath, len(data), removeErr)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -152,12 +147,28 @@ func (box *Box) docIAL(p string) (ret map[string]string) {
|
||||||
ret = readDocIAL(data)
|
ret = readDocIAL(data)
|
||||||
if nil == ret {
|
if nil == ret {
|
||||||
logging.LogWarnf("tree [%s] is corrupted", filePath)
|
logging.LogWarnf("tree [%s] is corrupted", filePath)
|
||||||
|
box.moveCorruptedData(filePath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cache.PutDocIAL(p, ret)
|
cache.PutDocIAL(p, ret)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (box *Box) moveCorruptedData(filePath string) {
|
||||||
|
filelock.UnlockFile(filePath)
|
||||||
|
base := filepath.Base(filePath)
|
||||||
|
to := filepath.Join(util.WorkspaceDir, "corrupted", time.Now().Format("2006-01-02-150405"), box.ID, base)
|
||||||
|
if copyErr := gulu.File.CopyFile(filePath, to); nil != copyErr {
|
||||||
|
logging.LogErrorf("copy corrupted data file [%s] failed: %s", filePath, copyErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if removeErr := os.RemoveAll(filePath); nil != removeErr {
|
||||||
|
logging.LogErrorf("remove corrupted data file [%s] failed: %s", filePath, removeErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logging.LogWarnf("moved corrupted data file [%s] to [%s]", filePath, to)
|
||||||
|
}
|
||||||
|
|
||||||
func readDocIAL(data []byte) (ret map[string]string) {
|
func readDocIAL(data []byte) (ret map[string]string) {
|
||||||
doc := map[string]interface{}{}
|
doc := map[string]interface{}{}
|
||||||
if err := gulu.JSON.UnmarshalJSON(data, &doc); nil != err {
|
if err := gulu.JSON.UnmarshalJSON(data, &doc); nil != err {
|
||||||
|
|
@ -165,7 +176,12 @@ func readDocIAL(data []byte) (ret map[string]string) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
props := doc["Properties"].(map[string]interface{})
|
propsArg := doc["Properties"]
|
||||||
|
if nil == propsArg {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
props := propsArg.(map[string]interface{})
|
||||||
ret = map[string]string{}
|
ret = map[string]string{}
|
||||||
for k, v := range props {
|
for k, v := range props {
|
||||||
ret[k] = v.(string)
|
ret[k] = v.(string)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue