I use the following code to copy files which works OK
The problem is that when we use this method to copy folder and items like node_js project with node_modules inside
in windows this can take a long time about 40 sec and in mac it takes 2 sec.
when doing trace (print the copied files) we saw that for example the io.copy
took 5 sec to copy short readme file
or json file , in each run it get stuck on different files , small size files like json readme etch
this is not consistent, in different run it stuck on different files ( if you run on same project).
we checked it on 3 different windows10 machine ( 1-3 years old) and 2 different macbook (3 years old) on exact same project. What it can be ?
func walk(src string, baseDir string, archive *zip.Writer) error {
return filepath.Walk(src, func(path string, info os.FileInfo, err error) (e error) {
if err != nil {
return err
}
if info.IsDir() {
return
}
header, err := zip.FileInfoHeader(info)
if err != nil {
return err
}
if baseDir != "" {
header.Name = filepath.ToSlash(getRelativePath(path, baseDir))
}
header.Method = zip.Deflate
writer, err := archive.CreateHeader(header)
if err != nil {
return err
}
file, err := os.Open(path)
if err != nil {
return err
}
defer func() {
e = CloseFile(file, e)
}()
_, err = io.Copy(writer, file)
return err
})
}
we are checking it almost 4 days and we didnt find any pattern :(