Skip to content

Commit

Permalink
update write permissions via in-built python functions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewprzh authored Jun 19, 2024
1 parent 9ece324 commit fd30980
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/projects/spades/pipeline/spades_pipeline/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_IRWXU)
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_IRWXU)
for f in files:
f = os.path.join(root, f)
s = os.stat(d)
os.chmod(f, s.st_mode | stat.S_IRWXU)


# 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):
Expand All @@ -939,7 +953,7 @@ 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:
os.system('chmod -R u+w '+dst)
add_user_write_permission_recursive(dst)

if not preserve_times:
for dirpath, _, filenames in os.walk(dst):
Expand Down

0 comments on commit fd30980

Please sign in to comment.