diff options
| author | ruki <[email protected]> | 2017-05-25 10:59:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-25 10:59:15 +0800 |
| commit | de4ea98d03332261d385a9096ebd9c4f6a3c50d1 (patch) | |
| tree | e7bcf87733d47a186966dcb8537b26b42981c4e7 /xmake/modules/privilege/sudo.lua | |
| parent | 79f3d173f193de0e30a4b57e903abe184b170082 (diff) | |
fix double quote pathenv for sudo
Diffstat (limited to 'xmake/modules/privilege/sudo.lua')
| -rw-r--r-- | xmake/modules/privilege/sudo.lua | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/xmake/modules/privilege/sudo.lua b/xmake/modules/privilege/sudo.lua index ea00957f2..b709d0db8 100644 --- a/xmake/modules/privilege/sudo.lua +++ b/xmake/modules/privilege/sudo.lua @@ -37,8 +37,19 @@ function _sudo(runner, cmd, ...) local program = find_sudo() assert(program, "sudo not found!") - -- run it with administrator permission and preserve parent environment - runner(program .. " 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 .. " PATH=\"" .. pathenv .. "\" " .. cmd, ...) + else + -- run it with administrator permission + runner(program .. " " .. cmd, ...) + end end -- sudo run shell with administrator permission and arguments list |
