util.datamanager: Ignore errors if the file is gone after removing it
authorKim Alvefur <zash@zash.se>
Sun, 26 Aug 2012 20:53:40 +0200
changeset 5103 5a1488369c35
parent 5102 ae8a993b598d
child 5104 27b45d2c19fe
child 5105 50688a2856f7
util.datamanager: Ignore errors if the file is gone after removing it
util/datamanager.lua
--- a/util/datamanager.lua	Sat Aug 25 01:33:01 2012 +0200
+++ b/util/datamanager.lua	Sun Aug 26 20:53:40 2012 +0200
@@ -309,6 +309,14 @@
 	return list;
 end
 
+local function do_remove(path)
+	local ok, err = os_remove(path);
+	if not ok and lfs.attributes(path, "mode") then
+		return ok, err;
+	end
+	return true
+end
+
 function purge(username, host)
 	local host_dir = format("%s/%s/", data_path, encode(host));
 	local deleted = 0;
@@ -316,10 +324,11 @@
 	for file in lfs.dir(host_dir) do
 		if lfs.attributes(host_dir..file, "mode") == "directory" then
 			local store = decode(file);
-			local ok, err = os_remove(getpath(username, host, store));
-			if not ok and not err:lower():match("no such") then errs[#errs+1] = err; end
-			local ok, err = os_remove(getpath(username, host, store, "list"));
-			if not ok and not err:lower():match("no such") then errs[#errs+1] = err; end
+			local ok, err = do_remove(getpath(username, host, store));
+			if not ok then errs[#errs+1] = err; end
+
+			local ok, err = do_remove(getpath(username, host, store, "list"));
+			if not ok then errs[#errs+1] = err; end
 		end
 	end
 	return #errs == 0, t_concat(errs, ", ");