|
@@ -334,7 +334,20 @@ func (ld *v1LayerDescriptor) Download(ctx context.Context, progressOutput progre
|
|
|
logrus.Debugf("Downloaded %s to tempfile %s", ld.ID(), ld.tmpFile.Name())
|
|
|
|
|
|
ld.tmpFile.Seek(0, 0)
|
|
|
- return ld.tmpFile, ld.layerSize, nil
|
|
|
+
|
|
|
+ // hand off the temporary file to the download manager, so it will only
|
|
|
+ // be closed once
|
|
|
+ tmpFile := ld.tmpFile
|
|
|
+ ld.tmpFile = nil
|
|
|
+
|
|
|
+ return ioutils.NewReadCloserWrapper(tmpFile, func() error {
|
|
|
+ tmpFile.Close()
|
|
|
+ err := os.RemoveAll(tmpFile.Name())
|
|
|
+ if err != nil {
|
|
|
+ logrus.Errorf("Failed to remove temp file: %s", tmpFile.Name())
|
|
|
+ }
|
|
|
+ return err
|
|
|
+ }), ld.layerSize, nil
|
|
|
}
|
|
|
|
|
|
func (ld *v1LayerDescriptor) Close() {
|