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.
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.
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.
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.
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 |
Fizzadar
left a comment
There was a problem hiding this comment.
@EricDriussi no worries re:times, thank you for finishing this up! Looks good to me will leave for Daan to have a double check too.
Adds copy operation suggested in #1121. Any and all feedback is welcome!
3.xat this time)scripts/dev-test.sh)scripts/dev-lint.sh)