Skip to content

Commit

Permalink
move in-line cleanup to declaring a default
Browse files Browse the repository at this point in the history
  • Loading branch information
bosorawis committed Feb 8, 2024
1 parent 2869fcb commit 4514279
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pluginutil/pluginutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +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, func() error {
return 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 @@ -253,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 4514279

Please sign in to comment.