Comparison

core/configmanager.lua @ 3609:954b1159f2f3

prosody, configmanager, certmanager: Relocate prosody.resolve_relative_path() to configmanager, and update certmanager (the only user of this function)
author Matthew Wild <mwild1@gmail.com>
date Wed, 10 Nov 2010 19:46:53 +0000
parent 3573:f31fa6520a4b
child 3610:2084959d4096
comparison
equal deleted inserted replaced
3608:ae0f83feaff4 3609:954b1159f2f3
11 setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, string.format; 11 setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, string.format;
12 12
13 13
14 local fire_event = prosody and prosody.events.fire_event or function () end; 14 local fire_event = prosody and prosody.events.fire_event or function () end;
15 15
16 local path_sep = package.config:sub(1,1);
17
16 module "configmanager" 18 module "configmanager"
17 19
18 local parsers = {}; 20 local parsers = {};
19 21
20 local config_mt = { __index = function (t, k) return rawget(t, "*"); end}; 22 local config_mt = { __index = function (t, k) return rawget(t, "*"); end};
60 return false; 62 return false;
61 end 63 end
62 64
63 function _M.set(host, section, key, value) 65 function _M.set(host, section, key, value)
64 return set(config, host, section, key, value); 66 return set(config, host, section, key, value);
67 end
68
69 -- Helper function to resolve relative paths (needed by config)
70 do
71 local rel_path_start = ".."..path_sep;
72 function resolve_relative_path(parent_path, path)
73 if path then
74 local is_relative;
75 if path_sep == "/" and path:sub(1,1) ~= "/" then
76 is_relative = true;
77 elseif path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\") then
78 is_relative = true;
79 end
80 if is_relative then
81 return parent_path..path_sep..path;
82 end
83 end
84 return path;
85 end
65 end 86 end
66 87
67 function load(filename, format) 88 function load(filename, format)
68 format = format or filename:match("%w+$"); 89 format = format or filename:match("%w+$");
69 90