Skip to content

Commit

Permalink
fix: chmod volume dir before deletion
Browse files Browse the repository at this point in the history
os.RemoveAll() fails if at least one subdir doesn't have write permissions.
See #834.
  • Loading branch information
mpatlasov committed Sep 4, 2024
1 parent d4481b1 commit 18bb6e9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/smb/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package smb
import (
"context"
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -223,6 +224,14 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
return nil, status.Errorf(codes.Internal, "archive subdirectory(%s, %s) failed with %v", internalVolumePath, archivedInternalVolumePath, err.Error())
}
} else {
if _, err2 := os.Lstat(internalVolumePath); err2 == nil {
err2 := filepath.WalkDir(internalVolumePath, func(path string, di fs.DirEntry, err error) error {
return os.Chmod(path, 0777)
})
if err2 != nil {
klog.V(2).Infof("failed to chmod subdirectory: %v", err2)
}
}
klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath)
if err = os.RemoveAll(internalVolumePath); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete subdirectory: %v", err.Error())
Expand Down

0 comments on commit 18bb6e9

Please sign in to comment.