Add file.ensure_content

This commit is contained in:
Lars Mueller 2020-12-22 11:36:58 +01:00
parent 2e4f03c94e
commit f4ee51e543

@ -14,6 +14,14 @@ function write(filename, new_content)
return true return true
end end
function ensure_content(filename, ensured_content)
local content = read(filename)
if content ~= ensured_content then
return write(filename, ensured_content)
end
return true
end
function append(filename, new_content) function append(filename, new_content)
local file = io.open(filename, "a") local file = io.open(filename, "a")
if file == nil then return false end if file == nil then return false end