@@ -21,6 +21,8 @@ import (
21
21
"errors"
22
22
"fmt"
23
23
"os"
24
+ "path/filepath"
25
+ "runtime"
24
26
25
27
csicommon "sigs.k8s.io/secrets-store-csi-driver/pkg/csi-common"
26
28
internalerrors "sigs.k8s.io/secrets-store-csi-driver/pkg/errors"
@@ -225,6 +227,21 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
225
227
return & csi.NodeUnpublishVolumeResponse {}, nil
226
228
}
227
229
230
+ // for windows as the target path is not a mount point, we need to explicitly remove the contents from the
231
+ // dir to be able to cleanup the target path.
232
+ if runtime .GOOS == "windows" {
233
+ files , err := filepath .Glob (filepath .Join (targetPath , "*" ))
234
+ if err != nil {
235
+ klog .ErrorS (err , "failed to get files from target path" , "targetPath" , targetPath )
236
+ return nil , status .Error (codes .Internal , err .Error ())
237
+ }
238
+ for _ , file := range files {
239
+ if err = os .RemoveAll (file ); err != nil {
240
+ klog .ErrorS (err , "failed to delete file from target path" , "targetPath" , targetPath , "file" , file )
241
+ }
242
+ }
243
+ }
244
+
228
245
err = mount .CleanupMountPoint (targetPath , ns .mounter , false )
229
246
if err != nil && ! os .IsNotExist (err ) {
230
247
klog .ErrorS (err , "failed to clean and unmount target path" , "targetPath" , targetPath )
0 commit comments