A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

: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

authored by

Jeffrey Chen and committed by
GitHub
e7914f99 d3918094

+10 -2
+10 -2
kernel/util/ocr.go
··· 109 109 110 110 start := time.Now() 111 111 112 + assetsPath := GetDataAssetsAbsPath() 113 + assetsTextsPath := filepath.Join(assetsPath, "ocr-texts.json") 114 + 112 115 assetsTextsLock.Lock() 116 + // OCR 功能未开启且 ocr-texts.json 不存在时,如果 assetsTexts 为空则不创建文件 117 + if !TesseractEnabled && !filelock.IsExist(assetsTextsPath) && 0 == len(assetsTexts) { 118 + assetsTextsLock.Unlock() 119 + assetsTextsChanged.Store(false) 120 + return 121 + } 113 122 data, err := gulu.JSON.MarshalIndentJSON(assetsTexts, "", " ") 114 123 if err != nil { 115 124 logging.LogErrorf("marshal assets texts failed: %s", err) 125 + assetsTextsLock.Unlock() 116 126 return 117 127 } 118 128 assetsTextsLock.Unlock() 119 129 120 - assetsPath := GetDataAssetsAbsPath() 121 - assetsTextsPath := filepath.Join(assetsPath, "ocr-texts.json") 122 130 if err = filelock.WriteFile(assetsTextsPath, data); err != nil { 123 131 logging.LogErrorf("write assets texts failed: %s", err) 124 132 return