util.datamanager: Try to open in read+write mode, then retry with write mode if that fails (usually because it doesn't exist)
authorKim Alvefur <zash@zash.se>
Tue, 31 Jul 2012 23:34:11 +0200
changeset 5066 4be7093edde9
parent 5057 1e44678b5de2
child 5067 7db1056c63a9
util.datamanager: Try to open in read+write mode, then retry with write mode if that fails (usually because it doesn't exist)
util/datamanager.lua
--- a/util/datamanager.lua	Tue Jul 31 08:23:55 2012 +0200
+++ b/util/datamanager.lua	Tue Jul 31 23:34:11 2012 +0200
@@ -201,7 +201,10 @@
 	if not data then return; end
 	if callback(username, host, datastore) == false then return true; end
 	-- save the datastore
-	local f, msg = io_open(getpath(username, host, datastore, "list", true), "a");
+	local f, msg = io_open(getpath(username, host, datastore, "list", true), "r+");
+	if not f then
+		f, msg = io_open(getpath(username, host, datastore, "list", true), "w");
+	end
 	if not f then
 		log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil");
 		return;