mod_muc_webchat_url: Fix default url
[prosody-modules.git] / mod_storage_xmlarchive / datamanager_append_raw.lib.lua
blobfd5704057ad80cdd99ae80b1f82587c3e45d18a7
1 local io_open = io.open;
2 local dm = require "core.storagemanager".olddm;
4 -- Append a blob of data to a file
5 function dm.append_raw(username, host, datastore, ext, data)
6 if type(data) ~= "string" then return; end
7 local filename = dm.getpath(username, host, datastore, ext, true);
9 local ok;
10 local f, msg = io_open(filename, "r+");
11 if not f then
12 -- File did probably not exist, let's create it
13 f, msg = io_open(filename, "w");
14 if not f then
15 return nil, msg, "open";
16 end
17 end
19 local pos = f:seek("end");
21 ok, msg = f:write(data);
22 if not ok then
23 f:close();
24 return ok, msg, "write";
25 end
27 ok, msg = f:close();
28 if not ok then
29 return ok, msg;
30 end
32 return true, pos;
33 end