Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for new go-qcow2reader convert interface #2933

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/lima-vm/go-qcow2reader v0.4.0 => github.com/nirs/go-qcow2reader v0.0.0-20241121185158-cfa1a2779b8c
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ 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/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 Expand Up @@ -222,6 +220,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/nirs/go-qcow2reader v0.0.0-20241121185158-cfa1a2779b8c h1:RCI6h8f9WXT0Ek3AdES9B96If2vohSxZk46WFCCMfxk=
github.com/nirs/go-qcow2reader v0.0.0-20241121185158-cfa1a2779b8c/go.mod h1:ay45SlGOzU+2Vc21g5/lmQgPn7Hmf0JpPhm8cuOK1FI=
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
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
Loading