@@ -12,6 +12,7 @@ import (
1212	"github.com/abiosoft/colima/environment" 
1313	"github.com/abiosoft/colima/environment/host" 
1414	"github.com/abiosoft/colima/environment/vm/lima/limaconfig" 
15+ 	"github.com/abiosoft/colima/util" 
1516	"github.com/abiosoft/colima/util/downloader" 
1617	"github.com/sirupsen/logrus" 
1718)
@@ -32,7 +33,7 @@ func ImageCached(arch environment.Arch, runtime string) (limaconfig.File, bool)
3233
3334	image  :=  diskImageFile (downloader .CacheFilename (img .Location ))
3435
35- 	img .Location  =  image .Raw ()
36+ 	img .Location  =  image .Location ()
3637	img .Digest  =  "" 
3738
3839	return  img , image .Generated ()
@@ -65,8 +66,18 @@ func DownloadImage(arch environment.Arch, runtime string) (f limaconfig.File, er
6566	if  err  !=  nil  {
6667		return  f , err 
6768	}
69+ 
70+ 	diskImage  :=  diskImageFile (qcow2 )
71+ 
72+ 	// if qemu-img is missing, ignore raw conversion 
73+ 	if  err  :=  util .AssertQemuImg (); err  !=  nil  {
74+ 		img .Location  =  diskImage .String ()
75+ 		img .Digest  =  ""  // remove digest 
76+ 		return  img , nil 
77+ 	}
78+ 
6879	// convert from qcow2 to raw 
69- 	raw , err  :=  qcow2ToRaw (host , diskImageFile ( qcow2 ) )
80+ 	raw , err  :=  qcow2ToRaw (host , diskImage )
7081	if  err  !=  nil  {
7182		return  f , err 
7283	}
@@ -160,6 +171,14 @@ type diskImageFile string
160171func  (d  diskImageFile ) String () string  { return  strings .TrimSuffix (string (d ), ".raw" ) }
161172func  (d  diskImageFile ) Raw () string     { return  d .String () +  ".raw"  }
162173func  (d  diskImageFile ) Generated () bool  {
163- 	stat , err  :=  os .Stat (d .Raw ())
174+ 	stat , err  :=  os .Stat (d .Location ())
164175	return  err  ==  nil  &&  ! stat .IsDir ()
165176}
177+ 
178+ // Location returns the expected location of the image based on availability of qemu. 
179+ func  (d  diskImageFile ) Location () string  {
180+ 	if  err  :=  util .AssertQemuImg (); err  ==  nil  {
181+ 		return  d .Raw ()
182+ 	}
183+ 	return  d .String ()
184+ }
0 commit comments