configmanager: Delay importing LuaFileSystem until needed by an Include line
[prosody.git] / core / configmanager.lua
index e31dbd7233e7f1274ea8f842cb2256e55843c2ff..d175b54b3efd9feaaaf5e57b27a5dd382fe5498f 100644 (file)
@@ -7,14 +7,14 @@
 --
 
 local _G = _G;
-local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table =
-      setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table;
+local setmetatable, rawget, rawset, io, error, dofile, type, pairs, table =
+      setmetatable, rawget, rawset, io, error, dofile, type, pairs, table;
 local format, math_max = string.format, math.max;
 
 local fire_event = prosody and prosody.events.fire_event or function () end;
 
 local envload = require"util.envload".envload;
-local lfs = require "lfs";
+local deps = require"util.dependencies";
 local path_sep = package.config:sub(1,1);
 
 module "configmanager"
@@ -68,7 +68,6 @@ end
 
 -- Helper function to resolve relative paths (needed by config)
 do
-       local rel_path_start = ".."..path_sep;
        function resolve_relative_path(parent_path, path)
                if path then
                        -- Some normalization
@@ -78,7 +77,7 @@ do
                        local is_relative;
                        if path_sep == "/" and path:sub(1,1) ~= "/" then
                                is_relative = true;
-                       elseif path_sep == "\\" and (path:sub(1,1) ~= "/" and (path:sub(2,3) ~= ":\\" or path:sub(2,3) ~= ":/")) then
+                       elseif path_sep == "\\" and (path:sub(1,1) ~= "/" and (path:sub(2,3) ~= ":\\" and path:sub(2,3) ~= ":/")) then
                                is_relative = true;
                        end
                        if is_relative then
@@ -152,7 +151,7 @@ end
 -- Built-in Lua parser
 do
        local pcall, setmetatable = _G.pcall, _G.setmetatable;
-       local rawget, tostring = _G.rawget, _G.tostring;
+       local rawget = _G.rawget;
        parsers.lua = {};
        function parsers.lua.load(data, config_file, config)
                local env;
@@ -213,8 +212,12 @@ do
                end
                env.component = env.Component;
                
-               function env.Include(file, wildcard)
+               function env.Include(file)
                        if file:match("[*?]") then
+                               local lfs = deps.softreq "lfs";
+                               if not lfs then
+                                       error(format("Error expanding wildcard pattern in Include %q - LuaFileSystem not available", file));
+                               end
                                local path_pos, glob = file:match("()([^"..path_sep.."]+)$");
                                local path = file:sub(1, math_max(path_pos-2,0));
                                local config_path = config_file:gsub("[^"..path_sep.."]+$", "");