Skip to content

Commit 5e82845

Browse files
Update main.lua
Fix file verify function
1 parent 806801e commit 5e82845

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

highlightsync.koplugin/main.lua

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,28 @@ function Highlightsync:init()
2828
self.ui.menu:registerToMainMenu(self))
2929
end
3030

31-
local function fileExists(filename)
32-
local file = io.open(filename, "r")
33-
if file then
34-
file:close()
35-
return true
36-
else
37-
return false
38-
39-
end
40-
end
41-
4231

4332
function Highlightsync.onSync(local_path, cached_path, income_path)
4433

4534
local local_highlights = dofile(local_path)
35+
4636
local cached_highlights
47-
if cached_path ~= nil and fileExists(cached_path) then -- Aqui está o erro. O arquivo não existe, mas está tentando abrir
48-
cached_highlights = dofile(cached_path)
37+
local success, result = pcall(dofile, cached_path)
38+
if success then
39+
cached_highlights = result
4940
else
5041
cached_highlights = {}
5142
end
43+
5244
local income_highlights
53-
if income_path ~= nil and fileExists(income_path)then
54-
income_highlights = dofile(income_path)
45+
local success, result = pcall(dofile, income_path)
46+
if success then
47+
income_highlights = result
5548
else
5649
income_highlights = {}
5750
end
58-
local annotations = Merge.merge_highlights(local_highlights,income_highlights,cached_highlights)
51+
52+
local annotations = Merge.Merge_highlights(local_highlights,income_highlights,cached_highlights)
5953

6054
salt.save(annotations,SidecarDir .. "/" .. FileName .. ".lua",true) -- Save annotations local
6155
DataAnnotations = annotations

0 commit comments

Comments
 (0)