68 end |
70 end |
69 end |
71 end |
70 |
72 |
71 ------- API ------------- |
73 ------- API ------------- |
72 |
74 |
|
75 function set_data_path(path) |
|
76 data_path = path; |
|
77 end |
|
78 |
73 function getpath(username, host, datastore, ext) |
79 function getpath(username, host, datastore, ext) |
74 ext = ext or "dat"; |
80 ext = ext or "dat"; |
75 if username then |
81 if username then |
76 return format("data/%s/%s/%s.%s", encode(host), datastore, encode(username), ext); |
82 return format("%s/%s/%s/%s.%s", data_path, encode(host), datastore, encode(username), ext); |
77 elseif host then |
83 elseif host then |
78 return format("data/%s/%s.%s", encode(host), datastore, ext); |
84 return format("%s/%s/%s.%s", data_path, encode(host), datastore, ext); |
79 else |
85 else |
80 return format("data/%s.%s", datastore, ext); |
86 return format("%s/%s.%s", data_path, datastore, ext); |
81 end |
87 end |
82 end |
88 end |
83 |
89 |
84 function load(username, host, datastore) |
90 function load(username, host, datastore) |
85 local data, ret = loadfile(getpath(username, host, datastore)); |
91 local data, ret = loadfile(getpath(username, host, datastore)); |