mage icon indicating copy to clipboard operation
mage copied to clipboard

Improve sh.Copy

Open ntrrg opened this issue 5 years ago • 2 comments

Hello :smile: I want to improve sh.Copy adding support for multiple files and directories, but I was wondering:

  • For multiple files, the signature of sh.Copy will be func Copy(dst string, src ...string) error, so it should work as always but break code like func MyFunction(arg string, copyFunc func(string, string) error) error, is this important? obviously this might be easily fixed with func MultiCopy(dst string, src ...string) error, but that means one extra exported function

  • For directories, is there any reason why it doesn't support directories? I mean, is that intentional? or supporting directories would be fine?

ntrrg avatar Dec 20 '18 15:12 ntrrg

I think I would make copying multiple files and copying directories different. The main reason is that they have different failure modes. Copying one file is simple - open old, open new, copy bytes over. Copying multiples means that one file can succeed while others fail... I think it would be better to split them up into different functions so the ramifications of what you're doing are clear.

natefinch avatar Dec 21 '18 02:12 natefinch

So, this could be the best way to do this?

  • func Copy(dst, src string) error
  • func MultiCopy(dst string, src ...string) error
  • func CopyDir(dst, src string) error
  • func MultiCopyDir(dst string, src ...string) error

ntrrg avatar Dec 21 '18 03:12 ntrrg