Skip to content

Commit f8140c8

Browse files
authored
Prevent panic if dir is nil (#129)
1 parent 00f367e commit f8140c8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

provider/pkg/provider/command.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func (c *command) RunCreate(ctx context.Context, host *provider.HostClient, urn
7979
return id, err
8080
}
8181

82-
//
8382
func (c *command) RunUpdate(ctx context.Context, host *provider.HostClient, urn resource.URN) (string, error) {
8483
if c.Update != nil {
8584
stdout, stderr, id, err := c.run(ctx, *c.Update, host, urn)
@@ -131,6 +130,14 @@ func (c *commandContext) run(ctx context.Context, command string, host *provider
131130
cmd.Stdout = stdoutw
132131
cmd.Stderr = stderrw
133132
if c.Dir != nil {
133+
// Check if exists and is a directory.
134+
stat, err := os.Stat(*c.Dir)
135+
if err != nil {
136+
return "", "", "", fmt.Errorf("error looking up directory: %q", err)
137+
}
138+
if !stat.IsDir() {
139+
return "", "", "", fmt.Errorf("%s is not a directory", *c.Dir)
140+
}
134141
cmd.Dir = *c.Dir
135142
} else {
136143
cmd.Dir, err = os.Getwd()

0 commit comments

Comments
 (0)