util.datamanager: In append() collect status when closing file handle as it may fail...
authorKim Alvefur <zash@zash.se>
Fri, 11 Dec 2015 19:13:37 +0000 (20:13 +0100)
committerKim Alvefur <zash@zash.se>
Fri, 11 Dec 2015 19:13:37 +0000 (20:13 +0100)
util/datamanager.lua

index 1993d6a3a035ed2ea78a3da4f5fa9bf2ba76b877..4a371d2ce7652360ac2be1b43875e2f3c16eb788 100644 (file)
@@ -210,9 +210,10 @@ local function store(username, host, datastore, data)
 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 @@ local function append(username, host, datastore, ext, data)
        else
                return ok, msg;
        end
-       f:close();
+
+       ok, msg = f:close();
+       if not ok then
+               return ok, msg;
+       end
+
        return true;
 end