Avoid recalculation of partial_md5_checksum at each opening (#3352)

This is done by/for kosync plugin at each opening, because
the docsettings was re-opened and saved for this, but later
overwritten by the current koreader docsettings - so it was
redone each time. This correctly adds this partial_md5_checksum
to the current koreader docsettings, which will be saved on
document closing - so it will not be redone next time.
Note: this partial_md5_checksum is not (yet) used by anything.
pull/3357/head
poire-z 7 years ago committed by Frans de Jonge
parent 29707bd664
commit 561caadc5c

@ -120,13 +120,18 @@ end
-- Note that if PDF file size is around 1024, 4096, 16384, 65536, 262144
-- 1048576, 4194304, 16777216, 67108864, 268435456 or 1073741824, appending data
-- by highlighting in KOReader may change the digest value.
function Document:fastDigest()
function Document:fastDigest(docsettings)
if not self.file then return end
local file = io.open(self.file, 'rb')
if file then
local docsettings = require("docsettings"):open(self.file)
local tmp_docsettings = false
if not docsettings then -- if not provided, open/create it
docsettings = require("docsettings"):open(self.file)
tmp_docsettings = true
end
local result = docsettings:readSetting("partial_md5_checksum")
if not result then
logger.dbg("computing and storing partial_md5_checksum")
local md5 = require("ffi/MD5")
local lshift = bit.lshift
local step, size = 1024, 1024
@ -143,7 +148,9 @@ function Document:fastDigest()
result = m:sum()
docsettings:saveSetting("partial_md5_checksum", result)
end
docsettings:close()
if tmp_docsettings then
docsettings:close()
end
file:close()
return result
end

@ -82,7 +82,7 @@ function KOSync:onReaderReady()
-- Make sure checksum has been calculated at the very first time a document has been opened, to
-- avoid document saving feature to impact the checksum, and eventually impact the document
-- identity in the progress sync feature.
self.view.document:fastDigest()
self.view.document:fastDigest(self.ui.doc_settings)
end
function KOSync:addToMainMenu(menu_items)

Loading…
Cancel
Save