Skip to content

Commit

Permalink
Remove data file when there are no marks
Browse files Browse the repository at this point in the history
  • Loading branch information
metalinspired committed Oct 31, 2024
1 parent 65159d3 commit 901daa7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lua/harpoon/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,28 @@ function Data:sync()
error("Harpoon: unable to sync data, error reading data file")
end

local has_data = false

for k, v in pairs(self._data) do
data[k] = v

local _, ctx = next(v)

if next(ctx) then
has_data = true
break
end
end

pcall(write_data, data, self.config)
if has_data then
pcall(write_data, data, self.config)
else
local path = Path:new(fullpath(self.config))

if path:exists() then
path:rm()
end
end
end

M.Data = Data
Expand Down

0 comments on commit 901daa7

Please sign in to comment.