aboutsummaryrefslogtreecommitdiffstats
path: root/util/datamanager.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-03-01 16:44:59 +0100
committerKim Alvefur <zash@zash.se>2017-03-01 16:44:59 +0100
commit890c5b5f04a80bff51c01d6ca30d175a35d1a875 (patch)
tree6e5305f8ba273fecc5bbbbb05e146c37948c17bb /util/datamanager.lua
parent70941b5f818b6e94cce03c9b3c83e3169fae5f68 (diff)
downloadprosody-890c5b5f04a80bff51c01d6ca30d175a35d1a875.tar.gz
prosody-890c5b5f04a80bff51c01d6ca30d175a35d1a875.zip
util.datamanager: Ignore ENOENT (no such file) when loading data
Diffstat (limited to 'util/datamanager.lua')
-rw-r--r--util/datamanager.lua17
1 files changed, 13 insertions, 4 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua
index 585bb83d..52d0c0bf 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -39,6 +39,7 @@ local function fallocate(f, offset, len)
f:seek("set", offset);
return true;
end;
+local ENOENT = 2;
pcall(function()
local pposix = require "util.pposix";
raw_mkdir = pposix.mkdir or raw_mkdir; -- Doesn't trample on umask
@@ -122,8 +123,12 @@ local function getpath(username, host, datastore, ext, create)
end
local function load(username, host, datastore)
- local data, err = envloadfile(getpath(username, host, datastore), {});
+ local data, err, errno = envloadfile(getpath(username, host, datastore), {});
if not data then
+ if errno == ENOENT then
+ -- No such file, ok to ignore
+ return nil;
+ end
local mode = lfs.attributes(getpath(username, host, datastore), "mode");
if not mode then
log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, err, username or "nil", host or "nil");
@@ -145,9 +150,9 @@ end
local function atomic_store(filename, data)
local scratch = filename.."~";
- local f, ok, msg;
+ local f, ok, msg, errno;
- f, msg = io_open(scratch, "w");
+ f, msg, errno = io_open(scratch, "w");
if not f then
return nil, msg;
end
@@ -295,8 +300,12 @@ end
local function list_load(username, host, datastore)
local items = {};
- local data, err = envloadfile(getpath(username, host, datastore, "list"), {item = function(i) t_insert(items, i); end});
+ local data, err, errno = envloadfile(getpath(username, host, datastore, "list"), {item = function(i) t_insert(items, i); end});
if not data then
+ if errno == ENOENT then
+ -- No such file, ok to ignore
+ return nil;
+ end
local mode = lfs.attributes(getpath(username, host, datastore, "list"), "mode");
if not mode then
log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, err, username or "nil", host or "nil");