diff --git a/frontend/document/document.lua b/frontend/document/document.lua index ae2c65166..8876691bf 100644 --- a/frontend/document/document.lua +++ b/frontend/document/document.lua @@ -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 diff --git a/plugins/kosync.koplugin/main.lua b/plugins/kosync.koplugin/main.lua index 856634b1c..4b90aae50 100644 --- a/plugins/kosync.koplugin/main.lua +++ b/plugins/kosync.koplugin/main.lua @@ -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)