mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 07:30:12 +01:00
🎨 Avoid creating empty ocr-texts.json when OCR is disabled (#16597)
- Skip file creation when OCR is disabled, file doesn't exist, and assetsTexts is empty - Fix potential deadlock by releasing lock when marshal fails
This commit is contained in:
parent
d391809442
commit
e7914f99f6
1 changed files with 10 additions and 2 deletions
|
|
@ -109,16 +109,24 @@ func SaveAssetsTexts() {
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
|
assetsPath := GetDataAssetsAbsPath()
|
||||||
|
assetsTextsPath := filepath.Join(assetsPath, "ocr-texts.json")
|
||||||
|
|
||||||
assetsTextsLock.Lock()
|
assetsTextsLock.Lock()
|
||||||
|
// OCR 功能未开启且 ocr-texts.json 不存在时,如果 assetsTexts 为空则不创建文件
|
||||||
|
if !TesseractEnabled && !filelock.IsExist(assetsTextsPath) && 0 == len(assetsTexts) {
|
||||||
|
assetsTextsLock.Unlock()
|
||||||
|
assetsTextsChanged.Store(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
data, err := gulu.JSON.MarshalIndentJSON(assetsTexts, "", " ")
|
data, err := gulu.JSON.MarshalIndentJSON(assetsTexts, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogErrorf("marshal assets texts failed: %s", err)
|
logging.LogErrorf("marshal assets texts failed: %s", err)
|
||||||
|
assetsTextsLock.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assetsTextsLock.Unlock()
|
assetsTextsLock.Unlock()
|
||||||
|
|
||||||
assetsPath := GetDataAssetsAbsPath()
|
|
||||||
assetsTextsPath := filepath.Join(assetsPath, "ocr-texts.json")
|
|
||||||
if err = filelock.WriteFile(assetsTextsPath, data); err != nil {
|
if err = filelock.WriteFile(assetsTextsPath, data); err != nil {
|
||||||
logging.LogErrorf("write assets texts failed: %s", err)
|
logging.LogErrorf("write assets texts failed: %s", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue