summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-24 09:34:02 +0800
committerGitHub <[email protected]>2017-05-24 09:34:02 +0800
commit59d3a4a90038971d8a7f875bd640bd76b9525dea (patch)
tree1f57392fc98ac89f4d0a12a4a4e7fd42120ea426
parenta23adbdd4bf9e45589ddae31c2744e2328114b6d (diff)
parent98a844e670ee733c1036947efd9099f7763fb544 (diff)
Merge pull request #116 from TitanSnow/sudo_uid
use SUDO_UID & SUDO_GID to know original uid & gid
-rw-r--r--xmake/core/base/privilege.lua28
1 files changed, 19 insertions, 9 deletions
diff --git a/xmake/core/base/privilege.lua b/xmake/core/base/privilege.lua
index 96426cbf3..c6b7bb0c2 100644
--- a/xmake/core/base/privilege.lua
+++ b/xmake/core/base/privilege.lua
@@ -36,16 +36,26 @@ function privilege.store()
return false
end
- -- find projectdir's owner
- local projectdir = xmake._PROJECT_DIR
- assert(projectdir)
- local owner = os.getown(projectdir)
- if not owner then
-
- -- fallback to current dir
- owner = os.getown(os.curdir())
+ local owner = {}
+ -- sudo will set SUDO_UID & SUDO_GID
+ -- so that can easily get original uid & gid
+ local sudo_uid = os.getenv("SUDO_UID")
+ local sudo_gid = os.getenv("SUDO_GID")
+ if sudo_uid and sudo_gid then
+ owner.uid = sudo_uid
+ owner.gid = sudo_gid
+ else
+ -- find projectdir's owner
+ local projectdir = xmake._PROJECT_DIR
+ assert(projectdir)
+ owner = os.getown(projectdir)
if not owner then
- return false
+
+ -- fallback to current dir
+ owner = os.getown(os.curdir())
+ if not owner then
+ return false
+ end
end
end