From c3bb2263b7cd35edb99516f903f2a31e7290bf7e Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:44:37 +0200 Subject: [PATCH] DocSettings: check legacy history location only once (#11439) --- datastorage.lua | 1 + frontend/docsettings.lua | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/datastorage.lua b/datastorage.lua index eda3b160f..ffed6826b 100644 --- a/datastorage.lua +++ b/datastorage.lua @@ -77,6 +77,7 @@ local function initDataDir() "data/dict", "data/tessdata", -- "docsettings", -- created when needed + -- "hashdocsettings", -- created when needed -- "history", -- legacy/obsolete sidecar files "ota", -- "patches", -- must be created manually by the interested user diff --git a/frontend/docsettings.lua b/frontend/docsettings.lua index c63db9322..de05ce9a7 100644 --- a/frontend/docsettings.lua +++ b/frontend/docsettings.lua @@ -35,6 +35,8 @@ local function isFile(file) return lfs.attributes(file, "mode") == "file" end +local is_history_location_enabled = isDir(HISTORY_DIR) + local doc_hash_cache = {} local is_hash_location_enabled @@ -164,7 +166,7 @@ function DocSettings:findSidecarFile(doc_path, no_legacy) return sidecar_file, location end end - if not no_legacy then + if is_history_location_enabled and not no_legacy then sidecar_file = self:getHistoryPath(doc_path) if isFile(sidecar_file) then return sidecar_file, "hist" -- for isSidecarFileNotInPreferredLocation() used in moveBookMetadata @@ -238,7 +240,7 @@ function DocSettings:open(doc_path) new.hash_sidecar_dir = new:getSidecarDir(doc_path, "hash") hash_sidecar_file = new.hash_sidecar_dir .. "/" .. new.sidecar_filename end - local history_file = new:getHistoryPath(doc_path) + local history_file = is_history_location_enabled and new:getHistoryPath(doc_path) -- Candidates list, in order of priority: local candidates_list = { @@ -257,9 +259,9 @@ function DocSettings:open(doc_path) -- Backup file of new sidecar file in hashdocsettings folder hash_sidecar_file and (hash_sidecar_file .. ".old") or "", -- Legacy history folder - history_file, + history_file or "", -- Backup file in legacy history folder - history_file .. ".old", + history_file and (history_file .. ".old") or "", -- Legacy kpdfview setting doc_path .. ".kpdfview.lua", }