util.stanza: Iterate on childtags instead of all childs.
[prosody.git] / util / datamanager.lua
index 9d96e5b37a5f733ec00665454da4a623fc155588..fbdfb581b66ef9208d37002c4e1b24125313f379 100644 (file)
@@ -145,7 +145,7 @@ function store(username, host, datastore, data)
        local f, msg = io_open(getpath(username, host, datastore, nil, true), "w+");
        if not f then
                log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil"));
-               return;
+               return nil, "Error saving to storage";
        end
        f:write("return ");
        append(f, data);
@@ -204,15 +204,22 @@ end
 function list_load(username, host, datastore)
        local data, ret = loadfile(getpath(username, host, datastore, "list"));
        if not data then
-               log("debug", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
-               return nil;
+               local mode = lfs.attributes(getpath(username, host, datastore, "list"), "mode");
+               if not mode then
+                       log("debug", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+                       return nil;
+               else -- file exists, but can't be read
+                       -- TODO more detailed error checking and logging?
+                       log("error", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+                       return nil, "Error reading storage";
+               end
        end
        local items = {};
        setfenv(data, {item = function(i) t_insert(items, i); end});
        local success, ret = pcall(data);
        if not success then
                log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
-               return nil;
+               return nil, "Error reading storage";
        end
        return items;
 end