Use fsync() for more robust setting files saving

Bump base for util.fsyncOpenedFile() and util.fsyncDirectory().

Use these to force flush to storage device when
saving luasetting, docsetting, and history.lua.
Also dont rotate them to .old until they are at least
60 seconds old.
Also make auto_save_paging_count count right.

Also bump crengine: open (as text) small or empty files
This commit is contained in:
poire-z
2019-12-10 23:00:08 +01:00
parent 1e1ceedd4d
commit 04d9a557aa
7 changed files with 73 additions and 23 deletions

View File

@@ -51,21 +51,27 @@ function LuaData:open(file_path, o) -- luacheck: ignore 312
end
end
local ok = pcall(dofile, new.file)
if ok then
logger.dbg("data is read from ", new.file)
else
logger.dbg(new.file, " is invalid, remove.")
os.remove(new.file)
local ok = false
if lfs.attributes(new.file, "mode") == "file" then
ok = pcall(dofile, new.file)
if ok then
logger.dbg("data is read from ", new.file)
else
logger.dbg(new.file, " is invalid, remove.")
os.remove(new.file)
end
end
if not ok then
for i=1, self.max_backups, 1 do
local backup_file = new.file..".old."..i
if pcall(dofile, backup_file) then
logger.dbg("data is read from ", backup_file)
break
else
logger.dbg(backup_file, " is invalid, remove.")
os.remove(backup_file)
if lfs.attributes(backup_file, "mode") == "file" then
if pcall(dofile, backup_file) then
logger.dbg("data is read from ", backup_file)
break
else
logger.dbg(backup_file, " is invalid, remove.")
os.remove(backup_file)
end
end
end
end