Comparison

util/datamanager.lua @ 5038:242c62ff8e77

util.datamanager: Add function for removing all data belonging to a user
author Kim Alvefur <zash@zash.se>
date Sat, 28 Jul 2012 21:31:54 +0200
parent 5032:c40ea227f8af
child 5045:4ba6940deed0
comparison
equal deleted inserted replaced
5037:c34fdcae6d29 5038:242c62ff8e77
251 end 251 end
252 end 252 end
253 return list; 253 return list;
254 end 254 end
255 255
256 function purge(username, host)
257 local host_dir = format("%s/%s/", data_path, encode(host));
258 local deleted = 0;
259 for file in lfs.dir(host_dir) do
260 if lfs.attributes(host_dir..file, "mode") == "directory" then
261 local store = decode(file);
262 deleted = deleted + (os_remove(getpath(username, host, store)) and 1 or 0);
263 deleted = deleted + (os_remove(getpath(username, host, store, "list")) and 1 or 0);
264 -- We this will generate loads of "No such file or directory", but do we care?
265 end
266 end
267 return deleted > 0, deleted;
268 end
269
256 return _M; 270 return _M;