aboutsummaryrefslogtreecommitdiff
path: root/atomic.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2021-04-04 19:50:04 +0200
committerorwell96 <orwell@bleipb.de>2021-04-04 19:55:21 +0200
commitedcc0d09178bfb64fbaa7620a7b0176d9b57b9d1 (patch)
tree9e5690670e5753de2534b177f700acf2aa26c013 /atomic.lua
parentf5689e9e9168a0f18d73651af18742244ff9939a (diff)
downloadadvtrains-edcc0d09178bfb64fbaa7620a7b0176d9b57b9d1.tar.gz
advtrains-edcc0d09178bfb64fbaa7620a7b0176d9b57b9d1.tar.bz2
advtrains-edcc0d09178bfb64fbaa7620a7b0176d9b57b9d1.zip
Open files in binary mode; also serialize carriage return
Bumps serialization version as CR escape would not be read correctly in older version
Diffstat (limited to 'atomic.lua')
-rw-r--r--atomic.lua12
1 files changed, 6 insertions, 6 deletions
diff --git a/atomic.lua b/atomic.lua
index 182cf42..4a48c27 100644
--- a/atomic.lua
+++ b/atomic.lua
@@ -65,7 +65,7 @@ local function save_atomic_move_file(filename)
end
local function open_file_and_save_callback(callback, filename)
- local file, err = io.open(filename, "w")
+ local file, err = io.open(filename, "wb")
if not file then
error("Failed opening file '"..filename.."' for write:\n"..err)
end
@@ -75,7 +75,7 @@ local function open_file_and_save_callback(callback, filename)
end
local function open_file_and_load_callback(filename, callback)
- local file, err = io.open(filename, "r")
+ local file, err = io.open(filename, "rb")
if not file then
error("Failed opening file '"..filename.."' for read:\n"..err)
end
@@ -97,7 +97,7 @@ function serialize_lib.load_atomic(filename, callback)
local cbfunc = callback or ser.read_from_fd
-- try <filename>
- local file, ret = io.open(filename, "r")
+ local file, ret = io.open(filename, "rb")
if file then
-- read the file using the callback
local success
@@ -117,7 +117,7 @@ function serialize_lib.load_atomic(filename, callback)
serialize_lib.log_warn(ret)
-- try <filename>.new
- file, ret = io.open(filename..".new", "r")
+ file, ret = io.open(filename..".new", "rb")
if file then
-- read the file using the callback
local success
@@ -151,7 +151,7 @@ function serialize_lib.save_atomic(data, filename, callback, config)
local cbfunc = callback or ser.write_to_fd
- local file, ret = io.open(filename..".new", "w")
+ local file, ret = io.open(filename..".new", "wb")
if file then
-- save the file using the callback
local success
@@ -189,7 +189,7 @@ function serialize_lib.save_atomic_multiple(parts_table, filename_prefix, callba
end
local success = false
- local file, ret = io.open(filename..".new", "w")
+ local file, ret = io.open(filename..".new", "wb")
if file then
-- save the file using the callback
success, ret = pcall(cbfunc, data, file, config)