comparison mod_storage_gdbm/mod_storage_gdbm.lua @ 1634:25441bd8b344

mod_storage_gdbm: Add purge action
author Kim Alvefur <zash@zash.se>
date Wed, 25 Mar 2015 17:45:53 +0100
parents 1d2dc6c74581
children b877b75eb973
comparison
equal deleted inserted replaced
1633:1d2dc6c74581 1634:25441bd8b344
149 cache[db_path] = db; 149 cache[db_path] = db;
150 end 150 end
151 return setmetatable({ _db = db; _path = db_path; store = store, typ = type }, driver_mt); 151 return setmetatable({ _db = db; _path = db_path; store = store, typ = type }, driver_mt);
152 end 152 end
153 153
154 function purge(_, user)
155 for dir in lfs.dir(base_path) do
156 local name, ext = dir:match("^(.-)%.a?db$");
157 if ext == ".db" then
158 open(_, name, "keyval"):set(user, nil);
159 elseif ext == ".adb" then
160 open(_, name, "archive"):delete(user);
161 end
162 end
163 return true;
164 end
165
154 function module.unload() 166 function module.unload()
155 for path, db in pairs(cache) do 167 for path, db in pairs(cache) do
156 gdbm.sync(db); 168 gdbm.sync(db);
157 gdbm.close(db); 169 gdbm.close(db);
158 end 170 end