mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
md5: centralize and deduplicate (#11003)
Document partial md5 hash is calculated by util.partialMD5() and stored in doc_settings as "partial_md5_checksum" on the first document opening.
This commit is contained in:
@@ -20,7 +20,7 @@ local DOCSETTINGS_HASH_DIR = DataStorage:getDocSettingsHashDir()
|
||||
local custom_metadata_filename = "custom_metadata.lua"
|
||||
|
||||
local is_hash_location_enabled
|
||||
local hash_path_cache = {}
|
||||
local doc_hash_cache = {}
|
||||
|
||||
function DocSettings.isHashLocationEnabled()
|
||||
if is_hash_location_enabled == nil then
|
||||
@@ -93,13 +93,13 @@ function DocSettings:getSidecarDir(doc_path, force_location)
|
||||
if location == "dir" then
|
||||
path = DOCSETTINGS_DIR .. path
|
||||
elseif location == "hash" then
|
||||
local hsh = hash_path_cache[doc_path]
|
||||
local hsh = doc_hash_cache[doc_path]
|
||||
if not hsh then
|
||||
local file = io.open(doc_path, 'rb')
|
||||
if not file then return path .. ".sdr" end
|
||||
hsh = util.partialMD5(file)
|
||||
file:close()
|
||||
hash_path_cache[doc_path] = hsh
|
||||
hsh = util.partialMD5(doc_path)
|
||||
if not hsh then -- fallback to "doc"
|
||||
return path .. ".sdr"
|
||||
end
|
||||
doc_hash_cache[doc_path] = hsh
|
||||
logger.dbg("DocSettings: Caching new partial MD5 hash for", doc_path, "as", hsh)
|
||||
else
|
||||
logger.dbg("DocSettings: Using cached partial MD5 hash for", doc_path, "as", hsh)
|
||||
|
||||
Reference in New Issue
Block a user