From 66ccd55ed4676b0b306829aa01ffdd4067c9960e Mon Sep 17 00:00:00 2001 From: LK4D4 Date: Mon, 14 Jul 2014 21:11:48 +0400 Subject: [PATCH] Some resource clean ups in archive Docker-DCO-1.1-Signed-off-by: Alexandr Morozov (github: LK4D4) --- archive/archive.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/archive/archive.go b/archive/archive.go index 2ba62f5363..bf6e0b7797 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -177,15 +177,15 @@ func addTarFile(path, name string, tw *tar.Writer) error { } if hdr.Typeflag == tar.TypeReg { - if file, err := os.Open(path); err != nil { + file, err := os.Open(path) + if err != nil { return err - } else { - _, err := io.Copy(tw, file) - if err != nil { - return err - } - file.Close() } + if _, err := io.Copy(tw, file); err != nil { + file.Close() + return err + } + file.Close() } return nil @@ -544,19 +544,19 @@ func CopyFileWithTar(src, dst string) (err error) { } defer srcF.Close() - tw := tar.NewWriter(w) hdr, err := tar.FileInfoHeader(srcSt, "") if err != nil { return err } hdr.Name = filepath.Base(dst) + tw := tar.NewWriter(w) + defer tw.Close() if err := tw.WriteHeader(hdr); err != nil { return err } if _, err := io.Copy(tw, srcF); err != nil { return err } - tw.Close() return nil }) defer func() {