summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-22 10:16:36 +0800
committerruki <[email protected]>2017-05-22 10:16:36 +0800
commitd57785f28f0c782dad8b089c96c009d801c2c65e (patch)
treea6327d2e8b6d444f469eb81f4ef8101640656f20
parent154cbd9137e037f0e930db04165fb91767b23636 (diff)
cache uid and improve tmpdir
-rw-r--r--xmake/core/base/os.lua34
1 files changed, 22 insertions, 12 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 5e325aaf4..02d96ad7e 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -33,6 +33,7 @@ local utils = require("base/utils")
local string = require("base/string")
-- save original interfaces
+os._uid = os._uid or os.uid
os._mkdir = os._mkdir or os.mkdir
os._rmdir = os._rmdir or os.rmdir
os._tmpdir = os._tmpdir or os.tmpdir
@@ -423,12 +424,7 @@ end
function os.tmpdir()
-- get a temporary directory for each user
- local tmpdir = os._tmpdir()
- if os.uid then
- tmpdir = path.join(tmpdir, ".xmake_" .. os.uid().euid)
- else
- tmpdir = path.join(tmpdir, ".xmake")
- end
+ local tmpdir = path.join(os._tmpdir(), ".xmake" .. (os.uid().euid or ""))
-- ensure this directory exist
if not os.isdir(tmpdir) then
@@ -630,6 +626,24 @@ function os.nuldev()
return xmake._NULDEV
end
+-- get uid
+function os.uid()
+
+ -- get it from cache first
+ if os._UID then
+ return os._UID
+ end
+
+ -- get uid
+ os._UID = {}
+ if os._uid then
+ os._UID = os._uid() or {}
+ end
+
+ -- ok?
+ return os._UID
+end
+
-- check run command as root
function os.isroot()
@@ -639,12 +653,8 @@ function os.isroot()
end
-- check it
- if os.host() == "windows" then
- -- TODO
- else
- if os.uid().euid == 0 then
- os._ISROOT = true
- end
+ if os.uid().euid == 0 then
+ os._ISROOT = true
end
-- not root?