From f4ee51e543c45c06f0d462540a04e809580e788f Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Tue, 22 Dec 2020 11:36:58 +0100 Subject: [PATCH] Add file.ensure_content --- file.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/file.lua b/file.lua index 0588978..956b33c 100644 --- a/file.lua +++ b/file.lua @@ -14,6 +14,14 @@ function write(filename, new_content) return true 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) local file = io.open(filename, "a") if file == nil then return false end