Software /
code /
prosody
Comparison
util/datamanager.lua @ 454:21105a005eef
Merge from waqas
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 28 Nov 2008 18:06:29 +0000 |
parent | 452:613c5c6bdce4 |
child | 456:27cb85d4059e |
comparison
equal
deleted
inserted
replaced
451:e9f269e5204e | 454:21105a005eef |
---|---|
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)); |