util.datamanager: Fix traceback from trying to purge when storage is empty or otherwise unaccessible (fixes #496)
authorKim Alvefur <zash@zash.se>
Wed, 13 May 2015 21:44:13 +0200
changeset 6684 0217a04722c7
parent 6683 ae34b12c4335
child 6685 63f5870f9afe
util.datamanager: Fix traceback from trying to purge when storage is empty or otherwise unaccessible (fixes #496)
util/datamanager.lua
--- a/util/datamanager.lua	Wed May 13 21:43:05 2015 +0200
+++ b/util/datamanager.lua	Wed May 13 21:44:13 2015 +0200
@@ -348,8 +348,12 @@
 
 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));