Software /
code /
prosody
Comparison
util/datamanager.lua @ 5103:5a1488369c35
util.datamanager: Ignore errors if the file is gone after removing it
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 26 Aug 2012 20:53:40 +0200 |
parent | 5095:dddbcd62183a |
child | 5118:0dc9e6c128c3 |
comparison
equal
deleted
inserted
replaced
5102:ae8a993b598d | 5103:5a1488369c35 |
---|---|
307 end | 307 end |
308 end | 308 end |
309 return list; | 309 return list; |
310 end | 310 end |
311 | 311 |
312 local function do_remove(path) | |
313 local ok, err = os_remove(path); | |
314 if not ok and lfs.attributes(path, "mode") then | |
315 return ok, err; | |
316 end | |
317 return true | |
318 end | |
319 | |
312 function purge(username, host) | 320 function purge(username, host) |
313 local host_dir = format("%s/%s/", data_path, encode(host)); | 321 local host_dir = format("%s/%s/", data_path, encode(host)); |
314 local deleted = 0; | 322 local deleted = 0; |
315 local errs = {}; | 323 local errs = {}; |
316 for file in lfs.dir(host_dir) do | 324 for file in lfs.dir(host_dir) do |
317 if lfs.attributes(host_dir..file, "mode") == "directory" then | 325 if lfs.attributes(host_dir..file, "mode") == "directory" then |
318 local store = decode(file); | 326 local store = decode(file); |
319 local ok, err = os_remove(getpath(username, host, store)); | 327 local ok, err = do_remove(getpath(username, host, store)); |
320 if not ok and not err:lower():match("no such") then errs[#errs+1] = err; end | 328 if not ok then errs[#errs+1] = err; end |
321 local ok, err = os_remove(getpath(username, host, store, "list")); | 329 |
322 if not ok and not err:lower():match("no such") then errs[#errs+1] = err; end | 330 local ok, err = do_remove(getpath(username, host, store, "list")); |
331 if not ok then errs[#errs+1] = err; end | |
323 end | 332 end |
324 end | 333 end |
325 return #errs == 0, t_concat(errs, ", "); | 334 return #errs == 0, t_concat(errs, ", "); |
326 end | 335 end |
327 | 336 |