120 return format("%s/%s/%s.%s", data_path, host, datastore, ext); |
121 return format("%s/%s/%s.%s", data_path, host, datastore, ext); |
121 end |
122 end |
122 end |
123 end |
123 |
124 |
124 local function load(username, host, datastore) |
125 local function load(username, host, datastore) |
125 local data, err = envloadfile(getpath(username, host, datastore), {}); |
126 local data, err, errno = envloadfile(getpath(username, host, datastore), {}); |
126 if not data then |
127 if not data then |
|
128 if errno == ENOENT then |
|
129 -- No such file, ok to ignore |
|
130 return nil; |
|
131 end |
127 local mode = lfs.attributes(getpath(username, host, datastore), "mode"); |
132 local mode = lfs.attributes(getpath(username, host, datastore), "mode"); |
128 if not mode then |
133 if not mode then |
129 log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, err, username or "nil", host or "nil"); |
134 log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, err, username or "nil", host or "nil"); |
130 return nil; |
135 return nil; |
131 else -- file exists, but can't be read |
136 else -- file exists, but can't be read |
143 return ret; |
148 return ret; |
144 end |
149 end |
145 |
150 |
146 local function atomic_store(filename, data) |
151 local function atomic_store(filename, data) |
147 local scratch = filename.."~"; |
152 local scratch = filename.."~"; |
148 local f, ok, msg; |
153 local f, ok, msg, errno; |
149 |
154 |
150 f, msg = io_open(scratch, "w"); |
155 f, msg, errno = io_open(scratch, "w"); |
151 if not f then |
156 if not f then |
152 return nil, msg; |
157 return nil, msg; |
153 end |
158 end |
154 |
159 |
155 ok, msg = f:write(data); |
160 ok, msg = f:write(data); |
293 return true; |
298 return true; |
294 end |
299 end |
295 |
300 |
296 local function list_load(username, host, datastore) |
301 local function list_load(username, host, datastore) |
297 local items = {}; |
302 local items = {}; |
298 local data, err = envloadfile(getpath(username, host, datastore, "list"), {item = function(i) t_insert(items, i); end}); |
303 local data, err, errno = envloadfile(getpath(username, host, datastore, "list"), {item = function(i) t_insert(items, i); end}); |
299 if not data then |
304 if not data then |
|
305 if errno == ENOENT then |
|
306 -- No such file, ok to ignore |
|
307 return nil; |
|
308 end |
300 local mode = lfs.attributes(getpath(username, host, datastore, "list"), "mode"); |
309 local mode = lfs.attributes(getpath(username, host, datastore, "list"), "mode"); |
301 if not mode then |
310 if not mode then |
302 log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, err, username or "nil", host or "nil"); |
311 log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, err, username or "nil", host or "nil"); |
303 return nil; |
312 return nil; |
304 else -- file exists, but can't be read |
313 else -- file exists, but can't be read |