Skip to content

Commit

Permalink
Update go-qcow2reader to 0.6.0
Browse files Browse the repository at this point in the history
This must be manual updated since this version made incompatible
changes.

With this version we cannot track conversion progress using the image,
since convert reads only the allocated extents of the image. We need to
pass the progress bar using convert.Options.

pb.ProgressBar need to be adapted to convert.Updater interface, so
progressbar returns now our own type. This can be used later for other
improvement like hiding the progress bar.

Signed-off-by: Nir Soffer <nirsof@gmail.com>
  • Loading branch information
nirs committed Nov 25, 2024
1 parent 9248baf commit d0610af
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 1 addition & 6 deletions pkg/nativeimgutil/nativeimgutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 7 additions & 10 deletions pkg/progressbar/progressbar.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package progressbar

import (
"io"
"os"
"time"

Expand All @@ -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)

Expand Down

0 comments on commit d0610af

Please # to comment.