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)
This commit is contained in:
parent
bdb6fee38c
commit
a590874f19
1 changed files with 5 additions and 2 deletions
|
@ -742,17 +742,20 @@ func NewTempArchive(src Archive, dir string) (*TempArchive, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
size := st.Size()
|
size := st.Size()
|
||||||
return &TempArchive{f, size}, nil
|
return &TempArchive{f, size, 0}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type TempArchive struct {
|
type TempArchive struct {
|
||||||
*os.File
|
*os.File
|
||||||
Size int64 // Pre-computed from Stat().Size() as a convenience
|
Size int64 // Pre-computed from Stat().Size() as a convenience
|
||||||
|
read int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (archive *TempArchive) Read(data []byte) (int, error) {
|
func (archive *TempArchive) Read(data []byte) (int, error) {
|
||||||
n, err := archive.File.Read(data)
|
n, err := archive.File.Read(data)
|
||||||
if err != nil {
|
archive.read += int64(n)
|
||||||
|
if err != nil || archive.read == archive.Size {
|
||||||
|
archive.File.Close()
|
||||||
os.Remove(archive.File.Name())
|
os.Remove(archive.File.Name())
|
||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
|
|
Loading…
Reference in a new issue