summaryrefslogtreecommitdiff
path: root/xmake/modules/privilege/sudo.lua
diff options
context:
space:
mode:
authorTitanSnow <[email protected]>2017-05-25 11:17:46 +0800
committerTitanSnow <[email protected]>2017-05-25 11:17:46 +0800
commitabb1d5705ecd01d906f63c7d838b73b7c2d1ede6 (patch)
tree6873180d5756c809117dc5c9f8f594aba56af435 /xmake/modules/privilege/sudo.lua
parentbbed6a5a8a80437afbb57540d77418084aabd950 (diff)
parent3768a8200a7699e1531c07ee5ab490e7d4f27b11 (diff)
Merge branch 'dev' into installtest
Diffstat (limited to 'xmake/modules/privilege/sudo.lua')
-rw-r--r--xmake/modules/privilege/sudo.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/xmake/modules/privilege/sudo.lua b/xmake/modules/privilege/sudo.lua
index d2e2de2cf..4eb5f6538 100644
--- a/xmake/modules/privilege/sudo.lua
+++ b/xmake/modules/privilege/sudo.lua
@@ -37,9 +37,19 @@ function _sudo(runner, cmd, ...)
local program = find_sudo()
assert(program, "sudo not found!")
- -- FIXME: deal with quotes in `os.getenv("PATH")`
- -- run it with administrator permission and preserve parent environment
- runner(program .. " env PATH=\"" .. os.getenv("PATH") .. "\" " .. cmd, ...)
+ -- get current path environment
+ local pathenv = os.getenv("PATH")
+ if pathenv and #pathenv > 0 then
+
+ -- handle double quote
+ pathenv = pathenv:gsub("\"", "\\\"")
+
+ -- run it with administrator permission and preserve parent environment
+ runner(program .. " env PATH=\"" .. pathenv .. "\" " .. cmd, ...)
+ else
+ -- run it with administrator permission
+ runner(program .. " " .. cmd, ...)
+ end
end
-- sudo run shell with administrator permission and arguments list