# HG changeset patch # User Kim Alvefur # Date 1480111867 -3600 # Node ID 7f9bf161f6408effc4b12f5fd4ecc71a50d8eb18 # Parent 544ee057a23fd70bc15f68393aba0b8c3e0c537b mod_storage_xmlarchive: Open XML file later, just before it is needed diff -r 544ee057a23f -r 7f9bf161f640 mod_storage_xmlarchive/mod_storage_xmlarchive.lua --- a/mod_storage_xmlarchive/mod_storage_xmlarchive.lua Fri Nov 25 23:08:18 2016 +0100 +++ b/mod_storage_xmlarchive/mod_storage_xmlarchive.lua Fri Nov 25 23:11:07 2016 +0100 @@ -118,13 +118,6 @@ else first_item, last_item = #items, 1; end - local ferr; - filename = dm.getpath(username .. "@" .. dates[d], module.host, self.store, "xml"); - xmlfile, ferr = io.open(filename); - if not xmlfile then - module:log("error", "Error: %s", ferr); - return; - end end local q_with, q_start, q_end = query.with, query.start, query["end"]; @@ -142,7 +135,16 @@ module:log("warn", "data[%q][%d].when is invalid", dates[d], i); break; end - if xmlfile and in_range + if not xmlfile then + local ferr; + filename = dm.getpath(username .. "@" .. dates[d], module.host, self.store, "xml"); + xmlfile, ferr = io.open(filename); + if not xmlfile then + module:log("error", "Error: %s", ferr); + return; + end + end + if in_range and (not q_with or i_with == q_with) and (not q_start or i_when >= q_start) and (not q_end or i_when <= q_end) then @@ -172,10 +174,10 @@ in_range = true; end end - end - if xmlfile then - xmlfile:close(); - xmlfile = nil; + if xmlfile then + xmlfile:close(); + xmlfile = nil; + end end end end