@@ -66,18 +66,27 @@ func runDecompression(d decompressor, decompressedFilePath string) (retErr error
6666 }
6767 defer d .close ()
6868
69- initMsg := progressBarPrefix + ": " + filepath .Base (decompressedFilePath )
70- finalMsg := initMsg + ": done"
71-
72- p , bar := utils .ProgressBar (initMsg , d .compressedFileSize (), finalMsg )
73- // Wait for bars to complete and then shut down the bars container
74- defer p .Wait ()
75-
76- compressedFileReaderProxy := bar .ProxyReader (compressedFileReader )
77- // Interrupts the bar goroutine. It's important that
78- // bar.Abort(false) is called before p.Wait(), otherwise
79- // can hang.
80- defer bar .Abort (false )
69+ filesize := d .compressedFileSize ()
70+ // bar.ProxyReader() returns nil when the bar is finished.
71+ // When the size is set to 0 the bar will finfish immediately, but this happens
72+ // in a different goroutine so it is race and only happens sometimes.
73+ // In general if the input is an empty file then we do not have to display a
74+ // progress bar at all as there is nothing to copy/extract really
75+ // https://github.com/containers/podman/issues/23281
76+ if filesize > 0 {
77+ initMsg := progressBarPrefix + ": " + filepath .Base (decompressedFilePath )
78+ finalMsg := initMsg + ": done"
79+
80+ p , bar := utils .ProgressBar (initMsg , filesize , finalMsg )
81+ // Wait for bars to complete and then shut down the bars container
82+ defer p .Wait ()
83+
84+ compressedFileReader = bar .ProxyReader (compressedFileReader )
85+ // Interrupts the bar goroutine. It's important that
86+ // bar.Abort(false) is called before p.Wait(), otherwise
87+ // can hang.
88+ defer bar .Abort (false )
89+ }
8190
8291 var decompressedFileWriter * os.File
8392
@@ -94,7 +103,7 @@ func runDecompression(d decompressor, decompressedFilePath string) (retErr error
94103 }
95104 }()
96105
97- if err = d .decompress (decompressedFileWriter , compressedFileReaderProxy ); err != nil {
106+ if err = d .decompress (decompressedFileWriter , compressedFileReader ); err != nil {
98107 logrus .Errorf ("Error extracting compressed file: %q" , err )
99108 return err
100109 }
0 commit comments