Skip to content

Commit

Permalink
Merge pull request #2933 from nirs/convert-interface
Browse files Browse the repository at this point in the history
Update go-qcow2reader to 0.6.0
  • Loading branch information
AkihiroSuda authored Nov 26, 2024
2 parents 9248baf + a65b114 commit 2c77ffc
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 2c77ffc

Please sign in to comment.