@@ -12,6 +12,7 @@ import (
1212 "net/url"
1313 "os"
1414 "path"
15+ "path/filepath"
1516 "regexp"
1617 "strings"
1718
@@ -226,7 +227,7 @@ func loadRpmImage(rpmImageBasePath string) (string, error) {
226227 return "" , fmt .Errorf (L ("error parsing: %s" ), string (out ))
227228}
228229
229- // IsImagePresent return true if the image is present.
230+ // IsImagePresent returns the image name if the image is present.
230231func IsImagePresent (image string ) (string , error ) {
231232 log .Debug ().Msgf ("Checking for %s" , image )
232233 out , err := utils .RunCmdOutput (zerolog .DebugLevel , "podman" , "images" , "--format={{ .Repository }}" , image )
@@ -354,18 +355,21 @@ func DeleteImage(name string, dryRun bool) error {
354355 return nil
355356}
356357
358+ var newRunner = utils .NewRunner
359+
357360// ExportImage saves a podman image based on its name to a specified directory.
358361// outputDir option expects already existing directory.
359362// If dryRun is set to true, nothing will be done, only messages logged to explain what would happen.
360363func ExportImage (name string , outputDir string , dryRun bool ) error {
361364 exists := imageExists (name )
362365 if exists {
363- saveCommand := []string {"podman" , "image" , "save" , "--quiet" , "-o" , path .Join (outputDir , name + ".tar" ), name }
366+ baseName , _ , _ := strings .Cut (filepath .Base (name ), ":" )
367+ saveCommand := []string {"podman" , "image" , "save" , "--quiet" , "-o" , path .Join (outputDir , baseName + ".tar" ), name }
364368 if dryRun {
365369 log .Info ().Msgf (L ("Would run %s" ), strings .Join (saveCommand , " " ))
366370 } else {
367371 log .Info ().Msgf (L ("Run %s" ), strings .Join (saveCommand , " " ))
368- err := utils . RunCmd (saveCommand [0 ], saveCommand [1 :]... )
372+ _ , err := newRunner (saveCommand [0 ], saveCommand [1 :]... ). Exec ( )
369373 if err != nil {
370374 return utils .Errorf (err , L ("Failed to export image %s" ), name )
371375 }
@@ -380,12 +384,12 @@ func imageExists(image string) bool {
380384}
381385
382386func RestoreImage (imageFile string , dryRun bool ) error {
383- restoreCommand := []string {"podman" , "image" , "import " , "--quiet" , imageFile }
387+ restoreCommand := []string {"podman" , "image" , "load " , "--quiet" , "-i " , imageFile }
384388 if dryRun {
385389 log .Info ().Msgf (L ("Would run %s" ), strings .Join (restoreCommand , " " ))
386390 } else {
387391 log .Info ().Msgf (L ("Run %s" ), strings .Join (restoreCommand , " " ))
388- err := utils . RunCmd (restoreCommand [0 ], restoreCommand [1 :]... )
392+ _ , err := newRunner (restoreCommand [0 ], restoreCommand [1 :]... ). Exec ( )
389393 if err != nil {
390394 return utils .Errorf (err , L ("Failed to restore image %s" ), imageFile )
391395 }
0 commit comments