Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for package managers storing files in read-only #1314

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 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_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):
Expand All @@ -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)