mage
mage copied to clipboard
Improve sh.Copy
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 befunc Copy(dst string, src ...string) error
, so it should work as always but break code likefunc MyFunction(arg string, copyFunc func(string, string) error) error
, is this important? obviously this might be easily fixed withfunc 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?
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.
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