Skip to content

Commit

Permalink
return blank cleanup func for plugin.InmemCreationFunc (#117)
Browse files Browse the repository at this point in the history
* return func instead of nil

* move in-line cleanup to declaring a default
  • Loading branch information
bosorawis committed Feb 13, 2024
1 parent 4321d38 commit e24d505
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pluginutil/pluginutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,18 @@ func CreatePlugin(plugin *PluginInfo, opt ...Option) (interface{}, func() error,
var file fs.File
var name string

cleanup := func() error {
return nil
}

switch {
case plugin == nil:
return nil, nil, fmt.Errorf("plugin is nil")

// Prioritize in-memory functions
case plugin.InmemCreationFunc != nil:
raw, err := plugin.InmemCreationFunc()
return raw, nil, err
return raw, cleanup, err

// If not in-memory we need a filename, whether direct on disk or from a container FS
case plugin.Path == "":
Expand Down Expand Up @@ -251,7 +255,7 @@ func CreatePlugin(plugin *PluginInfo, opt ...Option) (interface{}, func() error,
name = fmt.Sprintf("%s-%s", name, randSuffix)
dir := opts.withPluginExecutionDirectory

cleanup := func() error {
cleanup = func() error {
return os.Remove(filepath.Join(dir, name))
}
if dir == "" {
Expand Down

0 comments on commit e24d505

Please sign in to comment.