Skip to content

Commit

Permalink
Fix directory creation leading to already exist error
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-hb committed Feb 21, 2025
1 parent b642554 commit 0a48f3e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions internal/provider/resource/directory_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ func (r *DirectoryResource) Create(ctx context.Context, req resource.CreateReque

permissions := parsePermissions(plan.Permissions.ValueString())

err = client.CreateDirectory(ctx, plan.Path.ValueString(), os.FileMode(permissions))
if err != nil {
resp.Diagnostics.AddError(
"Error creating directory",
fmt.Sprintf("Could not create directory: %s", err),
)
return
if exists, _ := client.DirectoryExists(ctx, plan.Path.ValueString()); !exists {
err = client.CreateDirectory(ctx, plan.Path.ValueString(), os.FileMode(permissions))
if err != nil {
resp.Diagnostics.AddError(
"Error creating directory",
fmt.Sprintf("Could not create directory: %s", err),
)
return
}
}

// Set ownership if specified
Expand Down

0 comments on commit 0a48f3e

Please sign in to comment.