1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2025-05-13 22:30:21 +02:00

Prevent overwriting of tube DB backup file

This commit is contained in:
Jude Melton-Houghton 2022-08-12 21:06:59 -04:00
parent 23bf523c72
commit 659c9edac9

View File

@ -71,9 +71,15 @@ local function read_tube_db()
local file_content = file:read("*all") local file_content = file:read("*all")
io.close(file) io.close(file)
local backup_filename = filename .. ".bak"
pipeworks.logger("Moving teleport tube DB to mod storage from " .. filename) pipeworks.logger("Moving teleport tube DB to mod storage from " .. filename)
local backup_filename = filename .. ".bak"
pipeworks.logger("Backing up old file as " .. backup_filename) pipeworks.logger("Backing up old file as " .. backup_filename)
local backup_file = io.open(backup_filename, "r")
if backup_file then
io.close(backup_file)
error("Cannot back up teleport tube DB file " ..
"as a file already exists at " .. backup_filename)
end
assert(os.rename(filename, backup_filename)) assert(os.rename(filename, backup_filename))
if file_content and file_content ~= "" then if file_content and file_content ~= "" then