otiai10 / copy

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

Copies recursively if source is current directory. #96

Closed SameerPr closed 1 year ago

SameerPr commented 1 year ago

If the source is current directory and we specify a destination to be inside current working directory. it goes on a loop copying the destination folder recursively

cp.Copy(".", "dest")

Error:

open dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/dest/.idea/inspectionProfiles/Project_Default.xml: file name too long
otiai10 commented 1 year ago

Use temp dir as a temporary dest and then rename (mv) it to the dest which you really copy the src at.

SameerPr commented 1 year ago

I have used this for now

destination := "./dest" // defined destination
opt := Options{
    Skip: func(info os.FileInfo, src, dest string) (bool, error) {
        return strings.HasPrefix(src, path.Clean(destination)), nil
    },
}
err := Copy(source, destination, opt)
otiai10 commented 1 year ago

cool hack