Remove legacy document settings after flushing.

pull/2063/head
Hzj_jie 8 years ago
parent 861e50c0aa
commit 2085b774e2

@ -69,27 +69,27 @@ function DocSettings:open(docfile)
docfile:match(".*%.(.*)")..".lua" docfile:match(".*%.(.*)")..".lua"
end end
local candidates = {} new.candidates = {}
-- New sidecar file -- New sidecar file
table.insert(candidates, buildCandidate(new.sidecar_file)); table.insert(new.candidates, buildCandidate(new.sidecar_file));
-- Legacy sidecar file -- Legacy sidecar file
table.insert(candidates, buildCandidate( table.insert(new.candidates, buildCandidate(
self:getSidecarDir(docfile).."/".. self:getSidecarDir(docfile).."/"..
docfile:match(".*%/(.*)")..".lua")) docfile:match(".*%/(.*)")..".lua"))
-- Legacy history folder -- Legacy history folder
table.insert(candidates, buildCandidate(new.history_file)); table.insert(new.candidates, buildCandidate(new.history_file));
-- Legacy kpdfview setting -- Legacy kpdfview setting
table.insert(candidates, buildCandidate(docfile..".kpdfview.lua")); table.insert(new.candidates, buildCandidate(docfile..".kpdfview.lua"));
table.sort(candidates, function(l, r) table.sort(new.candidates, function(l, r)
if l == nil then if l == nil then
return false return false
elseif r == nil then elseif r == nil then
return true return true
else else
return l[2] > r[2] return l[2] > r[2]
end end
end) end)
for _, k in pairs(candidates) do for _, k in pairs(new.candidates) do
ok, stored = pcall(dofile, k[1]) ok, stored = pcall(dofile, k[1])
if ok then if ok then
break break
@ -135,6 +135,19 @@ function DocSettings:flush()
f_out:write(s_out) f_out:write(s_out)
f_out:write("\n") f_out:write("\n")
f_out:close() f_out:close()
if self.candidates ~= nil
and not G_reader_settings:readSetting(
"preserve_legacy_docsetting") then
for _, k in pairs(self.candidates) do
if k[1] ~= f then
os.remove(k[1])
-- We should not remove sidecar folder, as it may
-- contain Kindle history files.
end
end
end
break break
end end
end end

Loading…
Cancel
Save