set mod time after copy

This commit is contained in:
gutmet 2019-02-20 00:27:51 +01:00
parent ab2b1e8f6a
commit e251b8616e

View File

@ -32,6 +32,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"time"
)
// Copy copies src to dest, doesn't matter if src is a directory or a file
@ -65,15 +66,15 @@ func filecopy(src, dest string, info os.FileInfo) error {
if err = os.Chmod(f.Name(), info.Mode()); err != nil {
return err
}
if err = os.Chtimes(f.Name(), info.ModTime(), info.ModTime()); err != nil {
return err
}
s, err := os.Open(src)
if err != nil {
return err
}
defer s.Close()
_, err = io.Copy(f, s)
if err = os.Chtimes(f.Name(), time.Now().Local(), info.ModTime()); err != nil {
return err
}
return err
}