actually check we can run scm command for roles (#43315)

* actually check we can run scm command for roles
* a better error message than file not found
* more narrow exception hanlding
* refactor common functions for more extended use and further 'basic.py' separation
This commit is contained in:
Brian Coca 2018-07-31 13:04:05 -04:00 committed by GitHub
commit 222c907ffb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 38 deletions

View file

@ -32,6 +32,20 @@ class LockTimeout(Exception):
pass
def is_executable(path):
'''is the given path executable?
Limitations:
* Does not account for FSACLs.
* Most times we really want to know "Can the current user execute this
file" This function does not tell us that, only if an execute bit is set.
'''
# These are all bitfields so first bitwise-or all the permissions we're
# looking for, then bitwise-and with the file's mode to determine if any
# execute bits are set.
return ((stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) & os.stat(path)[stat.ST_MODE])
class FileLock:
'''
Currently FileLock is implemented via fcntl.flock on a lock file, however this