From af1f756a46c5da669897b841d4f753af1eaa9588 Mon Sep 17 00:00:00 2001 From: Bruno Bzeznik Date: Mon, 17 Jun 2024 16:09:01 +0200 Subject: [PATCH] Fix for package managers storing files in read-only update write permissions via in-built python functions fix: do not give exec permissions fix whatever typo is was --- .../spades/pipeline/spades_pipeline/support.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/projects/spades/pipeline/spades_pipeline/support.py b/src/projects/spades/pipeline/spades_pipeline/support.py index 341a9fd14..976ea9bd8 100644 --- a/src/projects/spades/pipeline/spades_pipeline/support.py +++ b/src/projects/spades/pipeline/spades_pipeline/support.py @@ -925,6 +925,20 @@ def is_int(value): return False +def add_user_write_permission_recursive(path): + s = os.stat(path) + os.chmod(path, s.st_mode | stat.S_IWUSR | stat.S_IRUSR) + for root, dirs, files in os.walk(path): + for d in dirs: + d = os.path.join(root, d) + s = os.stat(d) + os.chmod(d, s.st_mode | stat.S_IWUSR | stat.S_IRUSR) + for f in files: + f = os.path.join(root, f) + s = os.stat(d) + os.chmod(f, s.st_mode | stat.S_IWUSR | stat.S_IRUSR) + + # shutil.copyfile does not copy any metadata (time and permission), so one # cannot expect preserve_mode = False and preserve_times = True to work. def copy_tree(src, dst, preserve_times=True, preserve_mode=True): @@ -938,10 +952,12 @@ def copy_tree(src, dst, preserve_times=True, preserve_mode=True): # shutil.copytree preserves the timestamp, so we must update it afterwards. shutil.copytree(src, dst, copy_function = copy_fn) + if not preserve_mode: + add_user_write_permission_recursive(dst) if not preserve_times: for dirpath, _, filenames in os.walk(dst): os.utime(dirpath, None) for file in filenames: os.utime(os.path.join(dirpath, file), None) - +