diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-08-16 18:20:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-16 18:20:23 +0200 |
commit | 888163e95c89201ee28c0745508e1ba50c444164 (patch) | |
tree | 0ec9620463318ae65e21fdc478a2c617f62985af /python/vyos/util.py | |
parent | b17b8a0129f42c757c1e9a740664406e8da3dd42 (diff) | |
parent | 3ec77c9c878939f8c6e4eca62c4a2cddfef20db1 (diff) | |
download | vyos-1x-888163e95c89201ee28c0745508e1ba50c444164.tar.gz vyos-1x-888163e95c89201ee28c0745508e1ba50c444164.zip |
Merge pull request #510 from efficiosoft/vyos_template_rewrite
vyos.template: T2720: Rework vyos.template Python library
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index c07fef599..d27a8a3e7 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -240,7 +240,8 @@ def chown(path, user, group): if user is None or group is None: return False - if not os.path.exists(path): + # path may also be an open file descriptor + if not isinstance(path, int) and not os.path.exists(path): return False uid = getpwnam(user).pw_uid @@ -250,7 +251,8 @@ def chown(path, user, group): def chmod(path, bitmask): - if not os.path.exists(path): + # path may also be an open file descriptor + if not isinstance(path, int) and not os.path.exists(path): return if bitmask is None: return @@ -261,28 +263,25 @@ def chmod_600(path): """ make file only read/writable by owner """ from stat import S_IRUSR, S_IWUSR - if os.path.exists(path): - bitmask = S_IRUSR | S_IWUSR - os.chmod(path, bitmask) + bitmask = S_IRUSR | S_IWUSR + chmod(path, bitmask) def chmod_750(path): """ make file/directory only executable to user and group """ from stat import S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IXGRP - if os.path.exists(path): - bitmask = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP - os.chmod(path, bitmask) + bitmask = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP + chmod(path, bitmask) def chmod_755(path): """ make file executable by all """ from stat import S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IXGRP, S_IROTH, S_IXOTH - if os.path.exists(path): - bitmask = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | \ - S_IROTH | S_IXOTH - os.chmod(path, bitmask) + bitmask = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | \ + S_IROTH | S_IXOTH + chmod(path, bitmask) def makedir(path, user=None, group=None): |