util.ip: Fix protocol detection of IPv6 addresses beginning with : [Backported from...
[prosody.git] / util / datamanager.lua
index 4a4d62b3c098519f361912162f9a73e30209c960..a107d95c26904a697a949157f8caa706ca46a696 100644 (file)
@@ -163,7 +163,7 @@ local function atomic_store(filename, data)
        return nil, msg;
 end
 
-if prosody.platform ~= "posix" then
+if prosody and prosody.platform ~= "posix" then
        -- os.rename does not overwrite existing files on Windows
        -- TODO We could use Transactional NTFS on Vista and above
        function atomic_store(filename, data)
@@ -293,7 +293,7 @@ function users(host, store, typ)
 
        local mode, err = lfs.attributes(store_dir, "mode");
        if not mode then
-               return function() log("debug", err or (store_dir .. " does not exist")) end
+               return function() log("debug", "%s", err or (store_dir .. " does not exist")) end
        end
        local next, state = lfs.dir(store_dir);
        return function(state)
@@ -348,8 +348,12 @@ end
 
 function purge(username, host)
        local host_dir = format("%s/%s/", data_path, encode(host));
+       local ok, iter, state, var = pcall(lfs.dir, host_dir);
+       if not ok then
+               return ok, iter;
+       end
        local errs = {};
-       for file in lfs.dir(host_dir) do
+       for file in iter, state, var do
                if lfs.attributes(host_dir..file, "mode") == "directory" then
                        local store = decode(file);
                        local ok, err = do_remove(getpath(username, host, store));