util.datamanager: In append() collect status when closing file handle as it may fail (eg the implied flush)
authorKim Alvefur <zash@zash.se>
Fri, 11 Dec 2015 20:13:37 +0100
changeset 6997 507301531cf5
parent 6996 dc0c6b8dc638
child 6998 807b0b2ee545
util.datamanager: In append() collect status when closing file handle as it may fail (eg the implied flush)
util/datamanager.lua
--- a/util/datamanager.lua	Fri Dec 11 20:11:48 2015 +0100
+++ b/util/datamanager.lua	Fri Dec 11 20:13:37 2015 +0100
@@ -210,9 +210,10 @@
 end
 
 local function append(username, host, datastore, ext, data)
-	local f, msg = io_open(getpath(username, host, datastore, ext, true), "r+");
+	local filename = getpath(username, host, datastore, ext, true);
+	local f, msg = io_open(filename, "r+");
 	if not f then
-		f, msg = io_open(getpath(username, host, datastore, ext, true), "w");
+		f, msg = io_open(filename, "w");
 	end
 	if not f then
 		return nil, msg;
@@ -225,7 +226,12 @@
 	else
 		return ok, msg;
 	end
-	f:close();
+
+	ok, msg = f:close();
+	if not ok then
+		return ok, msg;
+	end
+
 	return true;
 end