prosody: Add prosody.resolve_relative_path() helper to change relative paths to be relative to the config file

Tue, 13 Jul 2010 13:55:18 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 13 Jul 2010 13:55:18 +0100
changeset 3354
b4ebda3fd6e9
parent 3353
cd3cbf361f8f
child 3355
9bb2da325d4d

prosody: Add prosody.resolve_relative_path() helper to change relative paths to be relative to the config file

prosody file | annotate | diff | comparison | revisions
--- a/prosody	Tue Jul 13 09:25:45 2010 +0100
+++ b/prosody	Tue Jul 13 13:55:18 2010 +0100
@@ -163,6 +163,23 @@
 	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";

mercurial