otiai10 / copy

Go copy directory recursively
https://pkg.go.dev/github.com/otiai10/copy
MIT License
722 stars 115 forks source link

Failed to symlink if file already exists #132

Closed starzation closed 9 months ago

starzation commented 10 months ago

Like the tittle said if the file is already exists (in destination folder) it will throw 'symlink error file exists'

There already a quick patch in vinegarhq/vinegar#322, Should the patch belong here or theres?

Issue (For log and more info): vinegarhq/vinegar#321 Code: vinegarhq/vinegar/internal/dirs/copy.go

otiai10 commented 10 months ago

Regarding this https://github.com/vinegarhq/vinegar/pull/322 and the change, it seems you're trying to copy Overlay to dest. Is it right?

We assume that users can check existence or properties of the root argument, the first argument the users give to cp.Copy func, by theirselves.

OnError or OnSymlink is to define behavior to handle something inside the folders, not the root folders.

Therefore, if you are talking about the root folders, you should separate the check before calling cp.Copy.


If my quick view above doesn't answer your question, let me ask you some clarification questions:

Given what 1, what 2 do you expect? What 3 did you see? What 4 is your proposal?

starzation commented 9 months ago

Regarding this vinegarhq/vinegar#322 and the change, it seems you're trying to copy Overlay to dest. Is it right? Yes that right.

Look like this is not the lib issue right? This mean we need to check if the file is already exists first if not then we call cp.Copy right? Since by default cp.Copy doesn't check if the file already exists and trying to copy the file

For more information: Overlay and dest is root folder and we trying to copy file inside Overlay into dest folder.

otiai10 commented 9 months ago

I think you understand it right.

In other words: as long as the user knows the names of what to be compared, the user should compare them by the user-side.

The methods "OnXxx" are provided because some cases happening during copying must be controlled by the user even the user couldn't anticipate the names of entries which would happen the cases.

Let me know if anything still unclear for you. I'm happy to hear to improve this pkg.

starzation commented 9 months ago

Thank you for your clarification. Also thank you for your assistance.

apprehensions commented 9 months ago

If i read copy behavior right, copy copies file no matter if the files exist in the destination directory, so why is the same not done for symlinks?

I expected copy to copy files from a source directory to a destination directory recursively, no matter if files are present or not in the destination.

otiai10 commented 9 months ago

@apprehensions Thank you for your comment.

Out discussion point is about "root" and "children". When we talk about "root", it's users' responsibility to check the validity.

When we talk about "children" under the root, we need a basic philosophy and some options to let users control the behavior.

apprehensions commented 9 months ago

Why are symlinks an exception?

otiai10 commented 9 months ago

Clarification: Are we talking about this? https://github.com/otiai10/copy/blob/1b0f2555a418af91c68cbd6c233a15e5e771ca96/copy.go#L314-L325

apprehensions commented 9 months ago

Yes, it seems copying the source symlinks even if it's links to somewhere that does not exist. It would hr better if the symlinks gets copied to the destination regardless if it does not exist much like regular files

otiai10 commented 9 months ago

I think I got your point:

Correct me if I'm understanding wrong.

apprehensions commented 9 months ago

Yes, the children (destination, copy) symlink should have the same behavior as copying regular files.

I apologize if I was explaining incorrectly.

otiai10 commented 8 months ago

Can you please open another issue for this?

apprehensions commented 8 months ago

@starzation can you confirm #145 fixes your problem?