Skip to content

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

Merged
merged 2 commits into from
May 22, 2015
Merged

Conversation

lexmag
Copy link
Member

@lexmag lexmag commented May 20, 2015

Closes #3155.
Cancels #3156.

@lexmag lexmag force-pushed the self-cp-fix branch 3 times, most recently from adee492 to b606e48 Compare May 20, 2015 21:04
@lexmag lexmag changed the title [WIP] Fix a file coping to itself Fix a file coping to itself May 20, 2015
@lexmag
Copy link
Member Author

lexmag commented May 20, 2015

@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
Copy link
Member

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?

Copy link
Member Author

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. :bowtie:

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

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.

josevalim added a commit that referenced this pull request May 22, 2015
Fix a file coping to itself
@josevalim josevalim merged commit c89670a into elixir-lang:master May 22, 2015
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

@lexmag lexmag deleted the self-cp-fix branch May 22, 2015 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Copy a file to itself will remove the file
2 participants