use SUDO_UID & SUDO_GID to know original uid & gid
sudo will set SUDO_UID & SUDO_GID
use this to go back original user
@@ -36,10 +36,19 @@ function privilege.store()
return false
end
+ 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)
- local owner = os.getown(projectdir)
+ owner = os.getown(projectdir)
if not owner then
-- fallback to current dir
@@ -48,6 +57,7 @@ function privilege.store()
return false
end
end
+ end
-- set gid
if os.gid(owner.gid).errno ~= 0 then
