-
-
Notifications
You must be signed in to change notification settings - Fork 448
Add files.copy operation #1446
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
base: 3.x
Are you sure you want to change the base?
Add files.copy operation #1446
Conversation
src/pyinfra/operations/files.py
Outdated
| dest_file_path = os.path.join(dest, os.path.basename(src)) | ||
| dest_file_exists = host.get_fact(File, dest_file_path) | ||
| if dest_file_exists and not overwrite: | ||
| raise OperationError(f"dest {dest_file_path} already exists and `overwrite` is unset") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should this raise an OperationError. For copy() to be idempotent, the destination file existing, should just be a noop right? Alternatively, you could compare hashes to see if the src file has changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed a noop would be a better fit here, although I still feel that an error should be raised in case dest_file_path already exists and is different from src. So maybe something like this?
if dest_file_exists and not overwrite:
if _file_equal(src, dest_file_path):
host.noop(f"{dest_file_path} already exists")
else:
raise OperationError(f"{dest_file_path} already exists and is different than src")Or maybe there's a better way to handle that case?
Also, in the snippet I use the _file_equal function, but that seems to be intended for local-remote hash comparisons.
Are you aware of any functions that might better fit this use case? Should I just create a new internal function based on this one for remote-remote hash comparison (what could be a nice name for it?)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you that the noop should only happen when the existing file at destination is the same.
I don't know if the _file_equal function can be used for remote-remote hash comparisons. @Fizzadar do you know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed _file_equal is for local <> remote, a new function seems best here, basically fact x2 and compare.
|
Hey! Sorry it took me forever to get back to this... Also, in the new |
Adds copy operation suggested in #1121. Any and all feedback is welcome!
3.xat this time)scripts/dev-test.sh)scripts/dev-lint.sh)