Browse code

pkg/archive: fix TempArchive cleanup w/ one read

This fixes the removal of TempArchives which can read with only one
read. Such archives weren't getting removed because EOF wasn't being
triggered.

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)

unclejack authored on 2014/11/21 02:34:35
Showing 1 changed files
... ...
@@ -742,17 +742,20 @@ func NewTempArchive(src Archive, dir string) (*TempArchive, error) {
742 742
 		return nil, err
743 743
 	}
744 744
 	size := st.Size()
745
-	return &TempArchive{f, size}, nil
745
+	return &TempArchive{f, size, 0}, nil
746 746
 }
747 747
 
748 748
 type TempArchive struct {
749 749
 	*os.File
750 750
 	Size int64 // Pre-computed from Stat().Size() as a convenience
751
+	read int64
751 752
 }
752 753
 
753 754
 func (archive *TempArchive) Read(data []byte) (int, error) {
754 755
 	n, err := archive.File.Read(data)
755
-	if err != nil {
756
+	archive.read += int64(n)
757
+	if err != nil || archive.read == archive.Size {
758
+		archive.File.Close()
756 759
 		os.Remove(archive.File.Name())
757 760
 	}
758 761
 	return n, err