otiai10 / copy

Go copy directory recursively

Home Page:https://pkg.go.dev/github.com/otiai10/copy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add an option to deep-copy symlinks

yasushi-saito opened this issue · comments

Can we have an option to copy symlinks? I'm imagining something like:

Opts struct {
  // Called if a symlink is found. If this function returns false, 
  // Copy copies the symlink itself. Else, Copy() follows the link.
  // If FollowSymlink=nil, Copy never follows symlinks.
  FollowSymlink func(path string) bool
}

func Copy(src, dest string, opt... Opts) error;

I can create a pull request if it looks good.

Can you please list up expected usecases of this option first?

From my perspective, there are 3 usecases when it comes to symlink:

  1. Hard copy
  2. Soft copy (create a link to the same resource)
  3. Ignore

What do you think?

Yes, the only feature I need now is deep-copies (i.e., follow all symlinks). So we can just have

type Opt struct { FollowSymlink bool }

I can't think a use case to ignore symlinks.

OK, then

  1. Hard copy ← is this what you want?
  2. Soft copy (create symlink) (follow) what you want
  3. Others (Skip?)

Is it right?

hmm, confusing... I'm still not sure what you want since your test cases are not descriptive enough and even failing.