prosody: Add prosody.resolve_relative_path() helper to change relative paths to be...
authorMatthew Wild <mwild1@gmail.com>
Tue, 13 Jul 2010 12:55:18 +0000 (13:55 +0100)
committerMatthew Wild <mwild1@gmail.com>
Tue, 13 Jul 2010 12:55:18 +0000 (13:55 +0100)
prosody

diff --git a/prosody b/prosody
index fd6a051c420fb5ef5936592fb44e4394961430c1..6ec9131e5a27aa49b196326ecb6e7db986d2d245 100755 (executable)
--- a/prosody
+++ b/prosody
@@ -163,6 +163,23 @@ function init_global_state()
        prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR, 
                          plugins = CFG_PLUGINDIR, data = CFG_DATADIR };
        
+       local path_sep = package.config:sub(1,1);
+       local rel_path_start = ".."..path_sep;
+       function prosody.resolve_relative_path(path)
+               if path then
+                       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) ~= ":\\") then
+                               is_relative = true;
+                       end
+                       if is_relative then
+                               return CFG_CONFIGDIR..path_sep..path;
+                       end
+               end
+               return path;
+       end
+       
        prosody.arg = _G.arg;
 
        prosody.platform = "unknown";