1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-31 10:11:17 +00:00

Fix to initial ~/.workload_automation deployment when sudoing

Only attempt to chown ~/.workload_automation to SUDO_USER if the
effective user is root.
This commit is contained in:
Sergei Trofimov 2015-04-24 10:05:13 +01:00
parent 704324ca77
commit 54e89a2118

View File

@ -151,19 +151,20 @@ def init_environment(env_root, dep_dir, extension_paths, overwrite_existing=Fals
for path in extension_paths: for path in extension_paths:
os.makedirs(path) os.makedirs(path)
# If running with sudo on POSIX, change the ownership to the real user. if os.getenv('USER') == 'root':
real_user = os.getenv('SUDO_USER') # If running with sudo on POSIX, change the ownership to the real user.
if real_user: real_user = os.getenv('SUDO_USER')
import pwd # done here as module won't import on win32 if real_user:
user_entry = pwd.getpwnam(real_user) import pwd # done here as module won't import on win32
uid, gid = user_entry.pw_uid, user_entry.pw_gid user_entry = pwd.getpwnam(real_user)
os.chown(env_root, uid, gid) uid, gid = user_entry.pw_uid, user_entry.pw_gid
# why, oh why isn't there a recusive=True option for os.chown? os.chown(env_root, uid, gid)
for root, dirs, files in os.walk(env_root): # why, oh why isn't there a recusive=True option for os.chown?
for d in dirs: for root, dirs, files in os.walk(env_root):
os.chown(os.path.join(root, d), uid, gid) for d in dirs:
for f in files: # pylint: disable=W0621 os.chown(os.path.join(root, d), uid, gid)
os.chown(os.path.join(root, f), uid, gid) for f in files: # pylint: disable=W0621
os.chown(os.path.join(root, f), uid, gid)
_env_root = os.getenv('WA_USER_DIRECTORY', os.path.join(_user_home, '.workload_automation')) _env_root = os.getenv('WA_USER_DIRECTORY', os.path.join(_user_home, '.workload_automation'))