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 file, err := os.Open(path); err != nil {
return err
} else {
_, err := io.Copy(tw, file)
file, err := os.Open(path)
if err != nil {
return err
}
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() {