Comparison

util/datamanager.lua @ 84:d0a0bac6815e

Added: Datastore support for hosts and global data in addition to users
author Waqas Hussain <waqas20@gmail.com>
date Thu, 09 Oct 2008 01:20:43 +0500
parent 0:3e3171b59028
child 87:059ef1c30844
comparison
equal deleted inserted replaced
83:79608fc8f98d 84:d0a0bac6815e
54 end 54 end
55 55
56 ------- API ------------- 56 ------- API -------------
57 57
58 function getpath(username, host, datastore) 58 function getpath(username, host, datastore)
59 return format("data/%s/%s/%s.dat", encode(host), datastore, encode(username)); 59 if username then
60 return format("data/%s/%s/%s.dat", encode(host), datastore, encode(username));
61 elseif host then
62 return format("data/%s/%s.dat", encode(host), datastore);
63 else
64 return format("data/%s.dat", datastore);
65 end
60 end 66 end
61 67
62 function load(username, host, datastore) 68 function load(username, host, datastore)
63 local data, ret = loadfile(getpath(username, host, datastore)); 69 local data, ret = loadfile(getpath(username, host, datastore));
64 if not data then log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end 70 if not data then log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end