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

bugfix: return err when load image instance failed #2112

Merged
Merged
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
25 changes: 7 additions & 18 deletions pkg/imageengine/buildah/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,11 @@ import (
"github.com/sealerio/sealer/common"
"github.com/sealerio/sealer/pkg/define/options"
"github.com/sealerio/sealer/utils/archive"
fsUtil "github.com/sealerio/sealer/utils/os/fs"
)

var LoadError = errors.Errorf("failed to load new image")

func (engine *Engine) Load(opts *options.LoadOptions) error {
// Download the input file if needed.
//if strings.HasPrefix(opts.Input, "https://") || strings.HasPrefix(opts.Input, "http://") {
// tmpdir, err := util.DefaultContainerConfig().ImageCopyTmpDir()
// if err != nil {
// return err
// }
// tmpfile, err := download.FromURL(tmpdir, loadOpts.Input)
// if err != nil {
// return err
// }
// defer os.Remove(tmpfile)
// loadOpts.Input = tmpfile
//}

imageSrc := opts.Input
if _, err := os.Stat(imageSrc); err != nil {
return err
Expand All @@ -71,15 +56,15 @@ func (engine *Engine) Load(opts *options.LoadOptions) error {
}
}()

tempDir, err := fsUtil.FS.MkTmpdir()
tempDir, err := os.MkdirTemp("", "sealer-load-tmp")
if err != nil {
return fmt.Errorf("failed to create %s, err: %v", tempDir, err)
}

defer func() {
err = fsUtil.FS.RemoveAll(tempDir)
err = os.RemoveAll(tempDir)
if err != nil {
logrus.Warnf("failed to delete %s: %v", tempDir, err)
logrus.Errorf("failed to delete %s: %v", tempDir, err)
}
}()

Expand Down Expand Up @@ -132,6 +117,10 @@ func (engine *Engine) Load(opts *options.LoadOptions) error {
return nil
})

if err != nil {
return fmt.Errorf("failed to load image instance %v", err)
}

// create a new manifest and add instance to it.
_, err = engine.CreateManifest(manifestName, &options.ManifestCreateOpts{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/imageengine/buildah/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ func (engine *Engine) Save(opts *options.SaveOptions) error {
}
}()

tempDir, err := fs.FS.MkTmpdir()
tempDir, err := os.MkdirTemp("", "sealer-save-tmp")
if err != nil {
return fmt.Errorf("failed to create %s, err: %v", tempDir, err)
}

defer func() {
err = fs.FS.RemoveAll(tempDir)
err = os.RemoveAll(tempDir)
if err != nil {
logrus.Warnf("failed to delete %s: %v", tempDir, err)
}
Expand Down