Mercurial > prosody-hg
comparison util/datamanager.lua @ 5095:dddbcd62183a
util.datamanager: Collect errors when deleting all stores of a user, but ignore "no such file"
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 25 Aug 2012 01:21:41 +0200 |
| parents | 7b298f8bcbcb |
| children | 5a1488369c35 |
comparison
equal
deleted
inserted
replaced
| 5094:e646c849d72f | 5095:dddbcd62183a |
|---|---|
| 310 end | 310 end |
| 311 | 311 |
| 312 function purge(username, host) | 312 function purge(username, host) |
| 313 local host_dir = format("%s/%s/", data_path, encode(host)); | 313 local host_dir = format("%s/%s/", data_path, encode(host)); |
| 314 local deleted = 0; | 314 local deleted = 0; |
| 315 local errs = {}; | |
| 315 for file in lfs.dir(host_dir) do | 316 for file in lfs.dir(host_dir) do |
| 316 if lfs.attributes(host_dir..file, "mode") == "directory" then | 317 if lfs.attributes(host_dir..file, "mode") == "directory" then |
| 317 local store = decode(file); | 318 local store = decode(file); |
| 318 deleted = deleted + (os_remove(getpath(username, host, store)) and 1 or 0); | 319 local ok, err = os_remove(getpath(username, host, store)); |
| 319 deleted = deleted + (os_remove(getpath(username, host, store, "list")) and 1 or 0); | 320 if not ok and not err:lower():match("no such") then errs[#errs+1] = err; end |
| 320 -- We this will generate loads of "No such file or directory", but do we care? | 321 local ok, err = os_remove(getpath(username, host, store, "list")); |
| 321 end | 322 if not ok and not err:lower():match("no such") then errs[#errs+1] = err; end |
| 322 end | 323 end |
| 323 return deleted > 0, deleted; | 324 end |
| 325 return #errs == 0, t_concat(errs, ", "); | |
| 324 end | 326 end |
| 325 | 327 |
| 326 return _M; | 328 return _M; |
