-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix a file coping to itself #3344
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
Conversation
adee492
to
b606e48
Compare
@josevalim this is ready for review. |
@@ -461,7 +461,7 @@ defmodule File do | |||
error will be returned. | |||
""" | |||
@spec cp(Path.t, Path.t, (Path.t, Path.t -> boolean)) :: :ok | {:error, posix} | |||
def cp(source, destination, callback \\ fn(_, _) -> true end) do | |||
def cp(source, destination, callback \\ &path_differs?/2) do |
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.
This means if the user is passing a custom function, they will need to add this logic himself. I don't think this is behaviour we want, right? We don't want to ever copy, we don't want to even invoke the callback. No?
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.
It feels that path_differs?/2
check out of callback makes this function more rigid.
My thoughts are to let user decide how to handle existence of the destination file even if it's the source itself. I think we could have a public alternative to path_differs?/2
. However, it's hard to say what the best for a user before we see it in use.
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.
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.
path_differs?/2
is moved out of callback.
❤️ 💚 💙 💛 💜 |
Closes #3155.
Cancels #3156.