diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua index 4cedd12d4..7c9d540ed 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/edit.lua @@ -445,6 +445,17 @@ local keyBindHandlers = { save = function() if readonly then return end local new = not fs.exists(filename) + local backup + if not new then + backup = filename .. "~" + for i = 1, math.huge do + if not fs.exists(backup) then + break + end + backup = filename .. "~" .. i + end + fs.copy(filename, backup) + end local f, reason = io.open(filename, "w") if f then local chars, firstLine = 0, true @@ -467,6 +478,9 @@ local keyBindHandlers = { else setStatus(reason) end + if not new then + fs.remove(backup) + end end, close = function() -- TODO ask to save if changed