cli: Clarify error message for unprivileged access

`os.path.exists("/run/weldr/api.socket")` returns False for users which have no
access. This leads to composer printing that the file does not exist, which is
misleading.

Since it's no possible to distinguish the two cases, fix this problem by
combining them and showing a single error message.
This commit is contained in:
Lars Karlitski 2018-09-24 09:09:49 +02:00 committed by Brian C. Lane
parent c2b0e8a8bb
commit bb40856f3e

View File

@ -81,10 +81,9 @@ if __name__ == '__main__':
errors = [] errors = []
# Check to see if the socket exists and can be accessed # Check to see if the socket exists and can be accessed
if not os.path.exists(opts.socket): if not os.access(opts.socket, os.R_OK|os.W_OK):
errors.append("%s does not exist" % opts.socket) errors.append("Cannot access '%s'. Is lorax-composer running and "
elif not os.access(opts.socket, os.R_OK|os.W_OK): "this user allowed to access it?" % opts.socket)
errors.append("This user cannot access %s" % opts.socket)
# No point in continuing if there are errors # No point in continuing if there are errors
if errors: if errors: