1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #7016 from LK4D4/fix_some_cleanups_in_archive

Some resource clean ups in archive
This commit is contained in:
Tibor Vass 2014-07-14 13:26:47 -04:00
commit dfbb291c40

View file

@ -177,15 +177,15 @@ func addTarFile(path, name string, tw *tar.Writer) error {
} }
if hdr.Typeflag == tar.TypeReg { if hdr.Typeflag == tar.TypeReg {
if file, err := os.Open(path); err != nil { file, err := os.Open(path)
return err
} else {
_, err := io.Copy(tw, file)
if err != nil { if err != nil {
return err return err
} }
if _, err := io.Copy(tw, file); err != nil {
file.Close() file.Close()
return err
} }
file.Close()
} }
return nil return nil
@ -544,19 +544,19 @@ func CopyFileWithTar(src, dst string) (err error) {
} }
defer srcF.Close() defer srcF.Close()
tw := tar.NewWriter(w)
hdr, err := tar.FileInfoHeader(srcSt, "") hdr, err := tar.FileInfoHeader(srcSt, "")
if err != nil { if err != nil {
return err return err
} }
hdr.Name = filepath.Base(dst) hdr.Name = filepath.Base(dst)
tw := tar.NewWriter(w)
defer tw.Close()
if err := tw.WriteHeader(hdr); err != nil { if err := tw.WriteHeader(hdr); err != nil {
return err return err
} }
if _, err := io.Copy(tw, srcF); err != nil { if _, err := io.Copy(tw, srcF); err != nil {
return err return err
} }
tw.Close()
return nil return nil
}) })
defer func() { defer func() {