diff --git a/go.mod b/go.mod index 0cf7ccf944f..711d5994a6e 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/google/go-cmp v0.6.0 github.com/google/yamlfmt v0.14.0 github.com/invopop/jsonschema v0.12.0 - github.com/lima-vm/go-qcow2reader v0.4.0 + github.com/lima-vm/go-qcow2reader v0.6.0 github.com/lima-vm/sshocker v0.3.4 github.com/mattn/go-isatty v0.0.20 github.com/mattn/go-shellwords v1.0.12 diff --git a/go.sum b/go.sum index a6f562bcd1c..699c54001b3 100644 --- a/go.sum +++ b/go.sum @@ -179,8 +179,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= -github.com/lima-vm/go-qcow2reader v0.4.0 h1:8tQp6azEvJLwktGMv4jOaFIq2sj5VX6EFX/UluKPzNM= -github.com/lima-vm/go-qcow2reader v0.4.0/go.mod h1:ay45SlGOzU+2Vc21g5/lmQgPn7Hmf0JpPhm8cuOK1FI= +github.com/lima-vm/go-qcow2reader v0.6.0 h1:dNstUGQxEUPbmiiVnu/cek2x7scrHe2VJy5JseLLflo= +github.com/lima-vm/go-qcow2reader v0.6.0/go.mod h1:ay45SlGOzU+2Vc21g5/lmQgPn7Hmf0JpPhm8cuOK1FI= github.com/lima-vm/sshocker v0.3.4 h1:5rn6vMkfqwZSZiBW+Udo505OIRhPB4xbLUDdEnFgWwI= github.com/lima-vm/sshocker v0.3.4/go.mod h1:QT4c7XNmeQTv79h5/8EgiS7U51B9BLenlXV7idCY0tE= github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2 h1:DZMFueDbfz6PNc1GwDRA8+6lBx1TB9UnxDQliCqR73Y= diff --git a/pkg/downloader/downloader.go b/pkg/downloader/downloader.go index 8a3160854c7..4057ca4a894 100644 --- a/pkg/downloader/downloader.go +++ b/pkg/downloader/downloader.go @@ -30,7 +30,7 @@ import ( var HideProgress bool // hideBar is used only for testing. -func hideBar(bar *pb.ProgressBar) { +func hideBar(bar *progressbar.ProgressBar) { bar.Set(pb.Static, true) } diff --git a/pkg/nativeimgutil/nativeimgutil.go b/pkg/nativeimgutil/nativeimgutil.go index 070786ae2a8..3f2a368ab35 100644 --- a/pkg/nativeimgutil/nativeimgutil.go +++ b/pkg/nativeimgutil/nativeimgutil.go @@ -78,13 +78,8 @@ func ConvertToRaw(source, dest string, size *int64, allowSourceWithBackingFile b if err != nil { return err } - conv, err := convert.New(convert.Options{}) - if err != nil { - return err - } bar.Start() - pra := progressbar.ProxyReaderAt{ReaderAt: srcImg, Bar: bar} - err = conv.Convert(destTmpF, &pra, srcImg.Size()) + err = convert.Convert(destTmpF, srcImg, convert.Options{Progress: bar}) bar.Finish() if err != nil { return fmt.Errorf("failed to convert image: %w", err) diff --git a/pkg/progressbar/progressbar.go b/pkg/progressbar/progressbar.go index 1e90954af6d..eea971dfbae 100644 --- a/pkg/progressbar/progressbar.go +++ b/pkg/progressbar/progressbar.go @@ -1,7 +1,6 @@ package progressbar import ( - "io" "os" "time" @@ -10,19 +9,17 @@ import ( "github.com/sirupsen/logrus" ) -type ProxyReaderAt struct { - io.ReaderAt - Bar *pb.ProgressBar +// ProgressBar adapts pb.ProgressBar to go-qcow2reader.convert.Updater interface. +type ProgressBar struct { + *pb.ProgressBar } -func (r *ProxyReaderAt) ReadAt(p []byte, off int64) (int, error) { - n, err := r.ReaderAt.ReadAt(p, off) - r.Bar.Add(n) - return n, err +func (b *ProgressBar) Update(n int64) { + b.Add64(n) } -func New(size int64) (*pb.ProgressBar, error) { - bar := pb.New64(size) +func New(size int64) (*ProgressBar, error) { + bar := &ProgressBar{pb.New64(size)} bar.Set(pb.Bytes, true)