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) - +