diff options
-rw-r--r-- | src/luarocks/cmd/path.lua | 18 | ||||
-rw-r--r-- | src/luarocks/core/cfg.lua | 4 | ||||
-rw-r--r-- | src/luarocks/core/util.lua | 11 |
3 files changed, 18 insertions, 15 deletions
diff --git a/src/luarocks/cmd/path.lua b/src/luarocks/cmd/path.lua index b1da4c0b..0038070b 100644 --- a/src/luarocks/cmd/path.lua +++ b/src/luarocks/cmd/path.lua | |||
@@ -35,32 +35,34 @@ function path_cmd.command(args) | |||
35 | local path_sep = cfg.export_path_separator | 35 | local path_sep = cfg.export_path_separator |
36 | 36 | ||
37 | if args.lr_path then | 37 | if args.lr_path then |
38 | util.printout(util.cleanup_path(lr_path, ';', cfg.lua_version)) | 38 | util.printout(util.cleanup_path(lr_path, ';', cfg.lua_version, true)) |
39 | return true | 39 | return true |
40 | elseif args.lr_cpath then | 40 | elseif args.lr_cpath then |
41 | util.printout(util.cleanup_path(lr_cpath, ';', cfg.lua_version)) | 41 | util.printout(util.cleanup_path(lr_cpath, ';', cfg.lua_version, true)) |
42 | return true | 42 | return true |
43 | elseif args.lr_bin then | 43 | elseif args.lr_bin then |
44 | util.printout(util.cleanup_path(lr_bin, path_sep)) | 44 | util.printout(util.cleanup_path(lr_bin, path_sep, nil, true)) |
45 | return true | 45 | return true |
46 | end | 46 | end |
47 | |||
48 | local clean_path = util.cleanup_path(os.getenv("PATH"), path_sep, nil, true) | ||
47 | 49 | ||
48 | if args.append then | 50 | if args.append then |
49 | lr_path = package.path .. ";" .. lr_path | 51 | lr_path = package.path .. ";" .. lr_path |
50 | lr_cpath = package.cpath .. ";" .. lr_cpath | 52 | lr_cpath = package.cpath .. ";" .. lr_cpath |
51 | lr_bin = os.getenv("PATH") .. path_sep .. lr_bin | 53 | lr_bin = clean_path .. path_sep .. lr_bin |
52 | else | 54 | else |
53 | lr_path = lr_path.. ";" .. package.path | 55 | lr_path = lr_path.. ";" .. package.path |
54 | lr_cpath = lr_cpath .. ";" .. package.cpath | 56 | lr_cpath = lr_cpath .. ";" .. package.cpath |
55 | lr_bin = lr_bin .. path_sep .. os.getenv("PATH") | 57 | lr_bin = lr_bin .. path_sep .. clean_path |
56 | end | 58 | end |
57 | 59 | ||
58 | local lpath_var, lcpath_var = util.lua_path_variables() | 60 | local lpath_var, lcpath_var = util.lua_path_variables() |
59 | 61 | ||
60 | util.printout(fs.export_cmd(lpath_var, util.cleanup_path(lr_path, ';', cfg.lua_version))) | 62 | util.printout(fs.export_cmd(lpath_var, util.cleanup_path(lr_path, ';', cfg.lua_version, args.append))) |
61 | util.printout(fs.export_cmd(lcpath_var, util.cleanup_path(lr_cpath, ';', cfg.lua_version))) | 63 | util.printout(fs.export_cmd(lcpath_var, util.cleanup_path(lr_cpath, ';', cfg.lua_version, args.append))) |
62 | if not args.no_bin then | 64 | if not args.no_bin then |
63 | util.printout(fs.export_cmd("PATH", util.cleanup_path(lr_bin, path_sep))) | 65 | util.printout(fs.export_cmd("PATH", util.cleanup_path(lr_bin, path_sep, nil, args.append))) |
64 | end | 66 | end |
65 | return true | 67 | return true |
66 | end | 68 | end |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 008ae7dc..99f609db 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
@@ -763,8 +763,8 @@ function cfg.init(detected, warning) | |||
763 | 763 | ||
764 | function cfg.init_package_paths() | 764 | function cfg.init_package_paths() |
765 | local lr_path, lr_cpath, lr_bin = cfg.package_paths() | 765 | local lr_path, lr_cpath, lr_bin = cfg.package_paths() |
766 | package.path = util.cleanup_path(package.path .. ";" .. lr_path, ";", lua_version) | 766 | package.path = util.cleanup_path(package.path .. ";" .. lr_path, ";", lua_version, true) |
767 | package.cpath = util.cleanup_path(package.cpath .. ";" .. lr_cpath, ";", lua_version) | 767 | package.cpath = util.cleanup_path(package.cpath .. ";" .. lr_cpath, ";", lua_version, true) |
768 | end | 768 | end |
769 | 769 | ||
770 | --- Check if platform was detected | 770 | --- Check if platform was detected |
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index d8f75d76..bd50ca0b 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua | |||
@@ -167,16 +167,16 @@ end | |||
167 | -- @param list string: A path string (from $PATH or package.path) | 167 | -- @param list string: A path string (from $PATH or package.path) |
168 | -- @param sep string: The separator | 168 | -- @param sep string: The separator |
169 | -- @param lua_version (optional) string: The Lua version to use. | 169 | -- @param lua_version (optional) string: The Lua version to use. |
170 | -- @param keep_last (optional) if true, keep last occurrence in case | 170 | -- @param keep_first (optional) if true, keep first occurrence in case |
171 | -- of duplicates; otherwise keep first occurrence. The default is false. | 171 | -- of duplicates; otherwise keep last occurrence. The default is false. |
172 | function util.cleanup_path(list, sep, lua_version, keep_last) | 172 | function util.cleanup_path(list, sep, lua_version, keep_first) |
173 | assert(type(list) == "string") | 173 | assert(type(list) == "string") |
174 | assert(type(sep) == "string") | 174 | assert(type(sep) == "string") |
175 | local parts = util.split_string(list, sep) | 175 | local parts = util.split_string(list, sep) |
176 | local final, entries = {}, {} | 176 | local final, entries = {}, {} |
177 | local start, stop, step | 177 | local start, stop, step |
178 | 178 | ||
179 | if keep_last then | 179 | if keep_first then |
180 | start, stop, step = 1, #parts, 1 | 180 | start, stop, step = 1, #parts, 1 |
181 | else | 181 | else |
182 | start, stop, step = #parts, 1, -1 | 182 | start, stop, step = #parts, 1, -1 |
@@ -192,11 +192,12 @@ function util.cleanup_path(list, sep, lua_version, keep_last) | |||
192 | end) | 192 | end) |
193 | end | 193 | end |
194 | if not entries[part] then | 194 | if not entries[part] then |
195 | local at = keep_last and #final+1 or 1 | 195 | local at = keep_first and #final+1 or 1 |
196 | table.insert(final, at, part) | 196 | table.insert(final, at, part) |
197 | entries[part] = true | 197 | entries[part] = true |
198 | end | 198 | end |
199 | end | 199 | end |
200 | |||
200 | return table.concat(final, sep) | 201 | return table.concat(final, sep) |
201 | end | 202 | end |
202 | 203 | ||