From b20cc7f5d7fea64c97b4810f71d35a544d6b2b42 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Tue, 31 Jul 2012 23:34:11 +0200
Subject: 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 | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'util')

diff --git a/util/datamanager.lua b/util/datamanager.lua
index 79be07b0..c8b905ac 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -201,7 +201,10 @@ function list_append(username, host, datastore, data)
 	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;
-- 
cgit v1.2.3