Mercurial > prosody-hg
comparison util/datamanager.lua @ 452:613c5c6bdce4
Added option core.data_path
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Fri, 28 Nov 2008 20:17:20 +0500 |
| parents | 6303b7454ad0 |
| children | 27cb85d4059e |
comparison
equal
deleted
inserted
replaced
| 449:c0a4a1e63d70 | 452:613c5c6bdce4 |
|---|---|
| 14 local indent = function(f, i) | 14 local indent = function(f, i) |
| 15 for n = 1, i do | 15 for n = 1, i do |
| 16 f:write("\t"); | 16 f:write("\t"); |
| 17 end | 17 end |
| 18 end | 18 end |
| 19 | |
| 20 local data_path = "data"; | |
| 19 | 21 |
| 20 module "datamanager" | 22 module "datamanager" |
| 21 | 23 |
| 22 | 24 |
| 23 ---- utils ----- | 25 ---- utils ----- |
| 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)); |
