Diff

prosodyctl @ 3999:58c0de7c6da0

prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
author Matthew Wild <mwild1@gmail.com>
date Tue, 04 Jan 2011 21:19:28 +0000
parent 3998:009d1ad84b49
child 4095:6ad7ed619d37
line wrap: on
line diff
--- a/prosodyctl	Tue Jan 04 21:18:35 2011 +0000
+++ b/prosodyctl	Tue Jan 04 21:19:28 2011 +0000
@@ -18,10 +18,22 @@
 
 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 
+local function is_relative(path)
+	local path_sep = package.config:sub(1,1);
+        return ((path_sep == "/" and path:sub(1,1) ~= "/")
+	or (path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\")))
+end
+
 -- Tell Lua where to find our libraries
 if CFG_SOURCEDIR then
-	package.path = CFG_SOURCEDIR.."/?.lua;"..package.path;
-	package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath;
+	local function filter_relative_paths(path)
+		if is_relative(path) then return ""; end
+	end
+	local function sanitise_paths(paths)
+		return (paths:gsub("[^;]+;?", filter_relative_paths):gsub(";;+", ";"));
+	end
+	package.path = sanitise_paths(CFG_SOURCEDIR.."/?.lua;"..package.path);
+	package.cpath = sanitise_paths(CFG_SOURCEDIR.."/?.so;"..package.cpath);
 end
 
 -- Substitute ~ with path to home directory in data path