mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-12 08:50:04 -04:00
Made edit create a temporary backup of the file being edited when saving, to avoid losing data when erroring while saving (e.g. out of memory). Closes #534.
This commit is contained in:
parent
07694cdb1f
commit
827f6ad4d8
@ -445,6 +445,17 @@ local keyBindHandlers = {
|
|||||||
save = function()
|
save = function()
|
||||||
if readonly then return end
|
if readonly then return end
|
||||||
local new = not fs.exists(filename)
|
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")
|
local f, reason = io.open(filename, "w")
|
||||||
if f then
|
if f then
|
||||||
local chars, firstLine = 0, true
|
local chars, firstLine = 0, true
|
||||||
@ -467,6 +478,9 @@ local keyBindHandlers = {
|
|||||||
else
|
else
|
||||||
setStatus(reason)
|
setStatus(reason)
|
||||||
end
|
end
|
||||||
|
if not new then
|
||||||
|
fs.remove(backup)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
close = function()
|
close = function()
|
||||||
-- TODO ask to save if changed
|
-- TODO ask to save if changed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user