From: Jason Ish Date: Mon, 13 Nov 2017 08:57:23 +0000 (+0100) Subject: fix restoration permission issue after update fail X-Git-Tag: 1.0.0a1~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f8f5a6823468c33dd5c681353bf1ca15f4c2db8;p=thirdparty%2Fsuricata-update.git fix restoration permission issue after update fail First attempt to just copy back the data of the files. Then attempt to copy the mode, as the mode may fail if the user running suricata-update doesn't own the files, but has permissions to write to them with group permissions. --- diff --git a/suricata/update/main.py b/suricata/update/main.py index da4ab49..3e87153 100644 --- a/suricata/update/main.py +++ b/suricata/update/main.py @@ -899,7 +899,17 @@ def copytree(src, dst): dst_path = os.path.join(dst, src_path[len(src) + 1:]) if not os.path.exists(os.path.dirname(dst_path)): os.makedirs(os.path.dirname(dst_path), mode=0o770) - shutil.copy2(src_path, dst_path) + shutil.copyfile(src_path, dst_path) + + # Also attempt to copy the stat bits, but this may fail + # if the owner of the file is not the same as the user + # running the program. + try: + shutil.copystat(src_path, dst_path) + except OSError as err: + logger.debug( + "Failed to copy stat info from %s to %s", src_path, + dst_path) def load_sources(config, suricata_version): files = {}