mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Merge pull request #24267 from aneeshusa/add-nice-error-msg-for-permission-denied
Have a nice error message if running as the wrong user.
This commit is contained in:
commit
4e19be2b7d
@ -154,12 +154,12 @@ def verify_files(files, user):
|
|||||||
try:
|
try:
|
||||||
pwnam = pwd.getpwnam(user)
|
pwnam = pwd.getpwnam(user)
|
||||||
uid = pwnam[2]
|
uid = pwnam[2]
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
err = ('Failed to prepare the Salt environment for user '
|
err = ('Failed to prepare the Salt environment for user '
|
||||||
'{0}. The user is not available.\n').format(user)
|
'{0}. The user is not available.\n').format(user)
|
||||||
sys.stderr.write(err)
|
sys.stderr.write(err)
|
||||||
sys.exit(salt.defaults.exitcodes.EX_NOUSER)
|
sys.exit(salt.defaults.exitcodes.EX_NOUSER)
|
||||||
|
|
||||||
for fn_ in files:
|
for fn_ in files:
|
||||||
dirname = os.path.dirname(fn_)
|
dirname = os.path.dirname(fn_)
|
||||||
try:
|
try:
|
||||||
@ -171,6 +171,14 @@ def verify_files(files, user):
|
|||||||
if not os.path.isfile(fn_):
|
if not os.path.isfile(fn_):
|
||||||
with salt.utils.fopen(fn_, 'w+') as fp_:
|
with salt.utils.fopen(fn_, 'w+') as fp_:
|
||||||
fp_.write('')
|
fp_.write('')
|
||||||
|
|
||||||
|
except IOError as err:
|
||||||
|
if err.errno != errno.EACCES:
|
||||||
|
raise
|
||||||
|
msg = 'No permissions to access "{0}", are you running as the correct user?\n'
|
||||||
|
sys.stderr.write(msg.format(fn_))
|
||||||
|
sys.exit(err.errno)
|
||||||
|
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
msg = 'Failed to create path "{0}" - {1}\n'
|
msg = 'Failed to create path "{0}" - {1}\n'
|
||||||
sys.stderr.write(msg.format(fn_, err))
|
sys.stderr.write(msg.format(fn_, err))
|
||||||
|
Loading…
Reference in New Issue
Block a user