From e7914f99f6ab7eda0f95ba0db66e724599cc65d7 Mon Sep 17 00:00:00 2001 From: Jeffrey Chen <78434827+TCOTC@users.noreply.github.com> Date: Tue, 16 Dec 2025 10:46:38 +0800 Subject: [PATCH] :art: 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 --- kernel/util/ocr.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/util/ocr.go b/kernel/util/ocr.go index b03824756..bc127e2ec 100644 --- a/kernel/util/ocr.go +++ b/kernel/util/ocr.go @@ -109,16 +109,24 @@ func SaveAssetsTexts() { start := time.Now() + assetsPath := GetDataAssetsAbsPath() + assetsTextsPath := filepath.Join(assetsPath, "ocr-texts.json") + 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, "", " ") if err != nil { logging.LogErrorf("marshal assets texts failed: %s", err) + assetsTextsLock.Unlock() return } assetsTextsLock.Unlock() - assetsPath := GetDataAssetsAbsPath() - assetsTextsPath := filepath.Join(assetsPath, "ocr-texts.json") if err = filelock.WriteFile(assetsTextsPath, data); err != nil { logging.LogErrorf("write assets texts failed: %s", err) return