diff options
| author | ruki <[email protected]> | 2017-05-24 09:34:02 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-24 09:34:02 +0800 |
| commit | 59d3a4a90038971d8a7f875bd640bd76b9525dea (patch) | |
| tree | 1f57392fc98ac89f4d0a12a4a4e7fd42120ea426 | |
| parent | a23adbdd4bf9e45589ddae31c2744e2328114b6d (diff) | |
| parent | 98a844e670ee733c1036947efd9099f7763fb544 (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.lua | 28 |
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 |
