]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
fix restoration permission issue after update fail
authorJason Ish <ish@unx.ca>
Mon, 13 Nov 2017 08:57:23 +0000 (09:57 +0100)
committerJason Ish <ish@unx.ca>
Mon, 13 Nov 2017 08:57:23 +0000 (09:57 +0100)
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.

suricata/update/main.py

index da4ab49484f08903517b3fc66a776f4e1317ad37..3e871533f4f65e096cd0262cf7aea22dfbf01d1e 100644 (file)
@@ -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 = {}