History: fix possible issues when saving and loading

Internal self.hist being an array, iterating it with 'pairs'
could have some strange effects. Best to use 'ipairs'.
reviewable/pr6212/r1
poire-z 4 years ago
parent c65c33d75f
commit 17c686628c

@ -84,11 +84,11 @@ end
function ReadHistory:_flush() function ReadHistory:_flush()
assert(self ~= nil) assert(self ~= nil)
local content = {} local content = {}
for k, v in pairs(self.hist) do for _, v in ipairs(self.hist) do
content[k] = { table.insert(content, {
time = v.time, time = v.time,
file = v.file file = v.file
} })
end end
local f = io.open(history_file, "w") local f = io.open(history_file, "w")
f:write("return " .. dump(content) .. "\n") f:write("return " .. dump(content) .. "\n")
@ -108,7 +108,8 @@ function ReadHistory:_read()
self.last_read_time = history_file_modification_time self.last_read_time = history_file_modification_time
local ok, data = pcall(dofile, history_file) local ok, data = pcall(dofile, history_file)
if ok and data then if ok and data then
for k, v in pairs(data) do self.hist = {}
for _, v in ipairs(data) do
table.insert(self.hist, buildEntry(v.time, v.file)) table.insert(self.hist, buildEntry(v.time, v.file))
end end
end end

Loading…
Cancel
Save