mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🐛 Notebook data may be corrupted during data synchronization https://github.com/siyuan-note/siyuan/issues/9594
This commit is contained in:
parent
a721bbe6f0
commit
70c56c8e25
24 changed files with 88 additions and 96 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue