diff options
| author | TitanSnow <[email protected]> | 2017-05-25 11:17:46 +0800 |
|---|---|---|
| committer | TitanSnow <[email protected]> | 2017-05-25 11:17:46 +0800 |
| commit | abb1d5705ecd01d906f63c7d838b73b7c2d1ede6 (patch) | |
| tree | 6873180d5756c809117dc5c9f8f594aba56af435 /xmake/modules/privilege/sudo.lua | |
| parent | bbed6a5a8a80437afbb57540d77418084aabd950 (diff) | |
| parent | 3768a8200a7699e1531c07ee5ab490e7d4f27b11 (diff) | |
Merge branch 'dev' into installtest
Diffstat (limited to 'xmake/modules/privilege/sudo.lua')
| -rw-r--r-- | xmake/modules/privilege/sudo.lua | 16 |
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 |
