Skip to content

Commit 8a53e8e

Browse files
Merge pull request #23323 from Luap99/machine-decompress-empty
pkg/machine/compression: skip decompress bar for empty file
2 parents 164ecb2 + f630eeb commit 8a53e8e

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

pkg/machine/compression/decompress.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

test/system/610-format.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function check_subcommand() {
149149
# ...or machine. But podman machine is ultra-finicky, it fails as root
150150
# or if qemu is missing. Instead of checking for all the possible ways
151151
# to skip it, just try running init. If it works, we can test it.
152-
run_podman '?' machine init --image-path=/dev/null mymachine
152+
run_podman '?' machine init --image=/dev/null mymachine
153153
if [[ $status -eq 0 ]]; then
154154
can_run_podman_machine=true
155155
extra_args_table+="

0 commit comments

Comments
 (0)