changeset 2290:4786bf0a9334

mod_storage_xmlarchive: Determine if a message is the first of day by checking if the list file exists before
author Kim Alvefur <zash@zash.se>
date Tue, 23 Aug 2016 23:39:57 +0200
parents aa984980a4dc
children 1eeda34d668b
files mod_storage_xmlarchive/mod_storage_xmlarchive.lua
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_storage_xmlarchive/mod_storage_xmlarchive.lua	Tue Aug 23 17:54:00 2016 +0200
+++ b/mod_storage_xmlarchive/mod_storage_xmlarchive.lua	Tue Aug 23 23:39:57 2016 +0200
@@ -5,6 +5,7 @@
 --
 -- luacheck: ignore unused self
 
+local lfs = require "lfs";
 local dm = require "core.storagemanager".olddm;
 local hmac_sha256 = require"util.hashes".hmac_sha256;
 local st = require"util.stanza";
@@ -37,13 +38,14 @@
 		return nil, err;
 	end
 
+	-- If the day-file is missing then we need to add it to the list of days
+	local first_of_day = not lfs.attributes(dm.getpath(username .. "@" .. day, module.host, self.store, "list"));
+
 	local offset = ok and err;
 
 	local id = day .. "-" .. hmac_sha256(username.."@"..day.."+"..offset, data, true):sub(-16);
 	ok, err = dm.list_append(username.."@"..day, module.host, self.store, { id = id, when = dt.datetime(when), with = with, offset = offset, length = #data });
-	if offset == 0 then
-		-- means the message is at the beginnig of the file, so it's a new day
-		-- so we add this new day to the "index"
+	if ok and first_of_day then
 		ok, err = dm.list_append(username, module.host, self.store, day);
 	end
 	if not ok then