@@ -423,34 +423,30 @@ func (p Plugin) Exec() error {
423423 tag := p .Build .Tags [0 ]
424424 fullImageName := fmt .Sprintf ("%s:%s" , p .Build .Repo , tag )
425425
426- if ! p .Build .BuildxLoad {
427- fmt .Printf ("Warning: To save images to tar, 'load' must be enabled. Adding the '--load' flag automatically.\n " )
428- p .Build .BuildxLoad = true
426+ if ! imageExists (fullImageName ) {
427+ return fmt .Errorf ("error: image %s not found in local daemon, cannot save to tar" , fullImageName )
429428 }
430429
431- if ! imageExists (fullImageName ) {
432- fmt .Printf ("Warning: Image %s not found in local daemon, cannot save to tar\n " , fullImageName )
433- } else {
434- dir := filepath .Dir (p .TarPath )
435- if err := os .MkdirAll (dir , 0755 ); err != nil {
436- fmt .Printf ("Warning: Failed to create directory for tar file: %v\n " , err )
437- }
430+ // Make sure the directory exists
431+ dir := filepath .Dir (p .TarPath )
432+ if err := os .MkdirAll (dir , 0755 ); err != nil {
433+ return fmt .Errorf ("error: failed to create directory for tar file: %v" , err )
434+ }
438435
439- // Save the image
440- fmt .Println ("Saving image to tar:" , p .TarPath )
441- saveCmd := commandSaveTar (fullImageName , p .TarPath )
442- saveCmd .Stdout = os .Stdout
443- saveCmd .Stderr = os .Stderr
444- trace (saveCmd )
436+ // Save the image
437+ fmt .Println ("Saving image to tar:" , p .TarPath )
438+ saveCmd := commandSaveTar (fullImageName , p .TarPath )
439+ saveCmd .Stdout = os .Stdout
440+ saveCmd .Stderr = os .Stderr
441+ trace (saveCmd )
445442
446- if err := saveCmd .Run (); err != nil {
447- fmt .Printf ("Warning: Failed to save image to tar: %v\n " , err )
448- } else {
449- fmt .Printf ("Successfully saved image to %s\n " , p .TarPath )
450- }
443+ if err := saveCmd .Run (); err != nil {
444+ return fmt .Errorf ("error: failed to save image to tar: %v" , err )
451445 }
446+
447+ fmt .Printf ("Successfully saved image to %s\n " , p .TarPath )
452448 } else {
453- fmt .Println ( "Warning: Cannot save image to tar, no tags specified" )
449+ return fmt .Errorf ( "error: cannot save image to tar, no tags specified" )
454450 }
455451 }
456452
@@ -984,6 +980,18 @@ func updateImageVersion(driverOpts *[]string, version string) {
984980func (p Plugin ) pushOnly () error {
985981 // If source tar path is provided, load the image first
986982 if p .SourceTarPath != "" {
983+ fileInfo , err := os .Stat (p .SourceTarPath )
984+ if err != nil {
985+ if os .IsNotExist (err ) {
986+ return fmt .Errorf ("source image tar file %s does not exist" , p .SourceTarPath )
987+ }
988+ return fmt .Errorf ("failed to access source image tar file: %w" , err )
989+ }
990+
991+ if ! fileInfo .Mode ().IsRegular () {
992+ return fmt .Errorf ("source image tar %s is not a regular file" , p .SourceTarPath )
993+ }
994+
987995 fmt .Println ("Loading image from tar:" , p .SourceTarPath )
988996 loadCmd := commandLoadTar (p .SourceTarPath )
989997 loadCmd .Stdout = os .Stdout
0 commit comments