Comparison

core/moduleapi.lua @ 9556:e4c09e335bd9

moduleapi: Prevent loading disabled module as dependency of enabled one Explicitly disabled module should stay disabled.
author Kim Alvefur <zash@zash.se>
date Thu, 25 Oct 2018 17:11:10 +0200
parent 9509:b57353f76c83
child 9686:e52e4e6e7ffb
comparison
equal deleted inserted replaced
9555:ed5a5ddcef17 9556:e4c09e335bd9
127 return f(); 127 return f();
128 end 128 end
129 129
130 function api:depends(name) 130 function api:depends(name)
131 local modulemanager = require"core.modulemanager"; 131 local modulemanager = require"core.modulemanager";
132 if self:get_option_inherited_set("modules_disabled", {}):contains(name) then
133 error("Dependency on disabled module mod_"..name);
134 end
132 if not self.dependencies then 135 if not self.dependencies then
133 self.dependencies = {}; 136 self.dependencies = {};
134 self:hook("module-reloaded", function (event) 137 self:hook("module-reloaded", function (event)
135 if self.dependencies[event.module] and not self.reloading then 138 if self.dependencies[event.module] and not self.reloading then
136 self:log("info", "Auto-reloading due to reload of %s:%s", event.host, event.module); 139 self:log("info", "Auto-reloading due to reload of %s:%s", event.host, event.module);
143 self:log("info", "Auto-unloading due to unload of %s:%s", event.host, event.module); 146 self:log("info", "Auto-unloading due to unload of %s:%s", event.host, event.module);
144 modulemanager.unload(self.host, self.name); 147 modulemanager.unload(self.host, self.name);
145 end 148 end
146 end); 149 end);
147 end 150 end
148 if self:get_option_inherited_set("modules_disabled", {}):contains(name) then
149 self:log("warn", "Loading prerequisite mod_%s despite it being disabled", name);
150 end
151 local mod = modulemanager.get_module(self.host, name) or modulemanager.get_module("*", name); 151 local mod = modulemanager.get_module(self.host, name) or modulemanager.get_module("*", name);
152 if mod and mod.module.host == "*" and self.host ~= "*" 152 if mod and mod.module.host == "*" and self.host ~= "*"
153 and modulemanager.module_has_method(mod, "add_host") then 153 and modulemanager.module_has_method(mod, "add_host") then
154 mod = nil; -- Target is a shared module, so we still want to load it on our host 154 mod = nil; -- Target is a shared module, so we still want to load it on our host
155 end 155 end