🐛 Notebook data may be corrupted during data synchronization https://github.com/siyuan-note/siyuan/issues/9594

This commit is contained in:
Daniel 2023-11-06 22:13:04 +08:00
parent a721bbe6f0
commit 70c56c8e25
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
24 changed files with 88 additions and 96 deletions

View file

@ -1,7 +1,6 @@
package model
import (
"io"
"os"
"path/filepath"
"runtime/debug"
@ -10,6 +9,7 @@ import (
"github.com/88250/gulu"
"github.com/dustin/go-humanize"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/task"
@ -57,7 +57,7 @@ func cleanNotExistAssetsTexts() {
for asset, _ := range util.AssetsTexts {
assetAbsPath := strings.TrimPrefix(asset, "assets")
assetAbsPath = filepath.Join(assetsPath, assetAbsPath)
if !gulu.File.IsExist(assetAbsPath) {
if !filelock.IsExist(assetAbsPath) {
toRemoves = append(toRemoves, asset)
}
}
@ -98,20 +98,12 @@ func FlushAssetsTextsJob() {
func LoadAssetsTexts() {
assetsPath := util.GetDataAssetsAbsPath()
assetsTextsPath := filepath.Join(assetsPath, "ocr-texts.json")
if !gulu.File.IsExist(assetsTextsPath) {
if !filelock.IsExist(assetsTextsPath) {
return
}
start := time.Now()
var err error
fh, err := os.OpenFile(assetsTextsPath, os.O_RDWR, 0644)
if nil != err {
logging.LogErrorf("open assets texts failed: %s", err)
return
}
defer fh.Close()
data, err := io.ReadAll(fh)
data, err := filelock.ReadFile(assetsTextsPath)
if nil != err {
logging.LogErrorf("read assets texts failed: %s", err)
return
@ -151,7 +143,7 @@ func SaveAssetsTexts() {
assetsPath := util.GetDataAssetsAbsPath()
assetsTextsPath := filepath.Join(assetsPath, "ocr-texts.json")
if err = gulu.File.WriteFileSafer(assetsTextsPath, data, 0644); nil != err {
if err = filelock.WriteFile(assetsTextsPath, data); nil != err {
logging.LogErrorf("write assets texts failed: %s", err)
return
}