comparison mod_persisthosts/mod_persisthosts.lua @ 6118:dde2803f7678

mod_persisthosts: Retrieve hosts from config instead of Prosody state This should avoid missing hosts that are activated after the one this module was loaded from.
author Kim Alvefur <zash@zash.se>
date Fri, 10 Jan 2025 16:19:27 +0100
parents 366fadb5c6e5
children c90aab23fb9b
comparison
equal deleted inserted replaced
6117:f267133c206f 6118:dde2803f7678
1 -- mod_persisthosts 1 -- mod_persisthosts
2 module:set_global(); 2 module:set_global();
3 3
4 local cm = require "core.configmanager";
4 local set = require"util.set"; 5 local set = require"util.set";
5 local stat = require"lfs".attributes; 6 local stat = require"lfs".attributes;
6 local resolve_relative_path = require"core.configmanager".resolve_relative_path; 7 local resolve_relative_path = require"core.configmanager".resolve_relative_path;
7 8
8 local vhost_path = module:get_option_string("persisthosts_path", "conf.d"); 9 local vhost_path = module:get_option_string("persisthosts_path", "conf.d");
9 local path_pattern = resolve_relative_path(prosody.paths.config, vhost_path) .. "/%s.cfg.lua"; 10 local path_pattern = resolve_relative_path(prosody.paths.config, vhost_path) .. "/%s.cfg.lua";
10 11
11 local original = set.new(); 12 local original = set.new();
12 original:include(prosody.hosts); 13 for host, config in pairs(cm.getconfig()) do
14 if config["defined"] then
15 original:add(host);
16 end
17 end
13 18
14 module:hook("host-activated", function(host) 19 module:hook("host-activated", function(host)
15 if not original:contains(host) then 20 if not original:contains(host) then
16 local path = path_pattern:format(host); 21 local path = path_pattern:format(host);
17 if not stat(path) then 22 if not stat(path) then