diff options
| author | ruki <[email protected]> | 2017-05-21 21:33:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-21 21:33:30 +0800 |
| commit | 83f448dc569b70410765dfe6241fabc351feb54f (patch) | |
| tree | 7bd1762bf8235d535980ff8223df6c50048a7365 /xmake/core/base/os.lua | |
| parent | b173fc383b9b1e80f0cbd2229d7b6d46ff75f0b6 (diff) | |
fix write nuldev bug as root
Diffstat (limited to 'xmake/core/base/os.lua')
| -rw-r--r-- | xmake/core/base/os.lua | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 21bec949c..d6e802472 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -630,7 +630,38 @@ end -- get the system null device function os.nuldev() - return xmake._NULDEV + if os.isroot() then + return os.tmpfile() + else + return xmake._NULDEV + end +end + +-- check run command as root +function os.isroot() + + -- get it from cache + if os._ISROOT ~= nil then + return os._ISROOT + end + + -- check it + if os.host() == "windows" then + -- TODO + else + local ok, code = os.iorun("id -u") + if ok and code and code:trim() == '0' then + os._ISROOT = true + end + end + + -- not root? + if os._ISROOT == nil then + os._ISROOT = false + end + + -- root? + return os._ISROOT end -- get version info |
