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

GitCopier: handle symlinks correctly #7

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

felixfontein
Copy link
Collaborator

Right now it copies the symlink's contents, which is usually not a good idea, and leads to exceptions if the symlink points to a directory or the destination does not exist.

@@ -95,7 +95,7 @@ def copy(self, from_path: StrPath, to_path: StrPath) -> None:

# Copy the file
dst_path = os.path.join(to_path, file_decoded)
shutil.copyfile(src_path, dst_path)
shutil.copyfile(src_path, dst_path, follow_symlinks=False)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's a relative symlink that points to outside the git checkout? Is this something we want to support?

Also, I'd replace copyfile with copy2 that preserves file metadata (probably in a separate PR).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's a relative symlink that points to outside the git checkout? Is this something we want to support?

If it points outside the git checkout then IMO it can be expected to be broken. If the collection is in a subdirectory of a git repository and the symlink points to a file in the repo outside the collection, well, that's a tricky case. I think for now it's OK to break it.

Also, I'd replace copyfile with copy2 that preserves file metadata (probably in a separate PR).

👍

@felixfontein felixfontein merged commit d6391de into ansible-community:main Sep 27, 2024
2 checks passed
@felixfontein felixfontein deleted the symlink branch September 27, 2024 18:51
@felixfontein
Copy link
Collaborator Author

@gotmax23 thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants