From a68378f14024bc1cebb15c5bd798d6d0dc7a46aa Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 25 May 2021 10:01:15 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=A4=8D=E5=88=B6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E4=BF=9D=E7=95=99=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/file.go b/file.go index bfb2115..09bdbe2 100644 --- a/file.go +++ b/file.go @@ -126,7 +126,6 @@ func (*GuluFile) CopyFile(source, dest string) (err error) { if err != nil { return err } - defer sourcefile.Close() if err = os.MkdirAll(filepath.Dir(dest), 0755); nil != err { @@ -137,17 +136,16 @@ func (*GuluFile) CopyFile(source, dest string) (err error) { if err != nil { return err } - defer destfile.Close() _, err = io.Copy(destfile, sourcefile) - if err == nil { + if nil == err { sourceinfo, err := os.Stat(source) - if err != nil { - err = os.Chmod(dest, sourceinfo.Mode()) + if nil == err { + os.Chmod(dest, sourceinfo.Mode()) + os.Chtimes(dest, sourceinfo.ModTime(), sourceinfo.ModTime()) } } - return nil } @@ -159,16 +157,15 @@ func (*GuluFile) CopyDir(source, dest string) (err error) { } // create dest dir - err = os.MkdirAll(dest, sourceinfo.Mode()) - if err != nil { + if err = os.MkdirAll(dest, sourceinfo.Mode()); err != nil { return err } + os.Chtimes(dest, sourceinfo.ModTime(), sourceinfo.ModTime()) directory, err := os.Open(source) if err != nil { return err } - defer directory.Close() objects, err := directory.Readdir(-1) @@ -193,6 +190,5 @@ func (*GuluFile) CopyDir(source, dest string) (err error) { } } } - return nil }