X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fdatamanager.lua;h=83f3dd13042d7607c8d5c2144a18f7512b4ec641;hb=2b120230b5ec5bcd129344ae908e73b89867d600;hp=ce4c5b5a22722270fb4fa86aecf478d3359248b9;hpb=a01d606ba9e434c181a45f4119386f16565f0070;p=prosody.git diff --git a/util/datamanager.lua b/util/datamanager.lua index ce4c5b5a..83f3dd13 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -209,17 +209,21 @@ local function store(username, host, datastore, data) return true; end +-- Append a blob of data to a file local function append(username, host, datastore, ext, data) + if type(data) ~= "string" then return; end local filename = getpath(username, host, datastore, ext, true); local ok; local f, msg = io_open(filename, "r+"); if not f then + -- File did probably not exist, let's create it f, msg = io_open(filename, "w"); if not f then - return nil, msg; + return nil, msg, "open"; end end + local pos = f:seek("end"); ok, msg = fallocate(f, pos, #data); if not ok then @@ -235,7 +239,7 @@ local function append(username, host, datastore, ext, data) ok, msg = f:write(data); if not ok then f:close(); - return ok, msg; + return ok, msg, "write"; end ok, msg = f:close(); @@ -243,7 +247,7 @@ local function append(username, host, datastore, ext, data) return ok, msg; end - return true; + return true, pos; end local function list_append(username, host, datastore, data) @@ -398,6 +402,7 @@ return { getpath = getpath; load = load; store = store; + append_raw = append; list_append = list_append; list_store = list_store; list_load = list_load;