From b396f0bb075d695e0d2d85868f2a988ff17429cb Mon Sep 17 00:00:00 2001 From: David Klaftenegger Date: Sat, 13 Feb 2016 00:57:28 +0100 Subject: [PATCH] Check result of file metadata changes Changing ownership and permissions is not supported on all filesystems. This patch prints a warning whenever it fails to set these properties, but continues without a fatal error. --- acertmgr.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/acertmgr.py b/acertmgr.py index c75ba84..5435eb1 100755 --- a/acertmgr.py +++ b/acertmgr.py @@ -191,8 +191,14 @@ def cert_put(domain, settings): # set owner and permissions uid = pwd.getpwnam(crt_user).pw_uid gid = grp.getgrnam(crt_group).gr_gid - os.chown(crt_path, uid, gid) - os.chmod(crt_path, int(crt_perm, 8)) + try: + os.chown(crt_path, uid, gid) + except OSError: + print('Warning: Could not set certificate file ownership!') + try: + os.chmod(crt_path, int(crt_perm, 8)) + except OSError: + print('Warning: Could not set certificate file permissions!') # restart/reload service subprocess.call(crt_notify.split())