2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00

Avoid writting highlights into read-only PDFs (#5889)

This commit is contained in:
Martín Fernández 2020-02-25 21:26:19 +01:00 committed by GitHub
parent 825b22dd6b
commit 5d103a41f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -1167,8 +1167,20 @@ end
--]]
function ReaderHighlight:exportToDocument(page, item)
local setting = G_reader_settings:readSetting("save_document")
if setting == "disable" then return end
logger.dbg("export highlight to document", item)
self.ui.document:saveHighlight(page, item)
local can_write = self.ui.document:saveHighlight(page, item)
if can_write == false and not self.warned_once then
self.warned_once = true
UIManager:show(InfoMessage:new{
text = _([[
Highlights in this document will be saved in the settings file, but they won't be written in the document itself because the file is in a read-only location.
If you wish your highlights to be saved in the document, just move it to a writable directory first.]]),
timeout = 5,
})
end
end
function ReaderHighlight:addNote()

View File

@ -175,6 +175,14 @@ function PdfDocument:saveHighlight(pageno, item)
local suffix = util.getFileNameSuffix(self.file)
if string.lower(suffix) ~= "pdf" then return end
if self.is_writable == nil then
local handle = io.open(self.file, 'r+b')
self.is_writable = handle ~= nil
if handle then handle:close() end
end
if self.is_writable == false then
return false
end
self.is_edited = true
-- will also need mupdf_h.lua to be evaluated once
-- but this is guaranteed at this point