From 8e33b7728daec397e2101f5e47147c2e7402a659 Mon Sep 17 00:00:00 2001 From: gutmet Date: Wed, 20 Feb 2019 00:19:41 +0100 Subject: [PATCH] filecopy: preserve modification time --- copy.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/copy.go b/copy.go index 67ccc5f..092d68a 100644 --- a/copy.go +++ b/copy.go @@ -5,6 +5,7 @@ Copied from https://github.com/otiai10/copy and slightly altered. The MIT License (MIT) +Copyright (c) 2019 Alexander Weinhold Copyright (c) 2018 otiai10 Permission is hereby granted, free of charge, to any person obtaining a copy @@ -31,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 @@ -64,6 +66,9 @@ 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(), time.Now().Local(), info.ModTime()); err != nil { + return err + } s, err := os.Open(src) if err != nil { return err