11package filesystem
22
33import (
4- "errors"
54 "fmt"
65 "os"
76 "path/filepath"
87
9- "golang.org/x/sys/windows"
10- "k8s.io/klog/v2"
8+ "github.com/kubernetes-csi/csi-proxy/pkg/utils"
119)
1210
1311// Implements the Filesystem OS API calls. All code here should be very simple
@@ -50,26 +48,6 @@ func (filesystemAPI) PathExists(path string) (bool, error) {
5048 return pathExists (path )
5149}
5250
53- func pathValid (path string ) (bool , error ) {
54- pathString , err := windows .UTF16PtrFromString (path )
55- if err != nil {
56- return false , fmt .Errorf ("invalid path: %w" , err )
57- }
58-
59- attrs , err := windows .GetFileAttributes (pathString )
60- if err != nil {
61- if errors .Is (err , windows .ERROR_PATH_NOT_FOUND ) || errors .Is (err , windows .ERROR_FILE_NOT_FOUND ) || errors .Is (err , windows .ERROR_INVALID_NAME ) {
62- return false , nil
63- }
64-
65- // GetFileAttribute returns user or password incorrect for a disconnected SMB connection after the password is changed
66- return false , fmt .Errorf ("failed to get path %s attribute: %w" , path , err )
67- }
68-
69- klog .V (6 ).Infof ("Path %s attribute: %d" , path , attrs )
70- return attrs != windows .INVALID_FILE_ATTRIBUTES , nil
71- }
72-
7351// PathValid determines whether all elements of a path exist
7452//
7553// https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-path?view=powershell-7
@@ -78,7 +56,7 @@ func pathValid(path string) (bool, error) {
7856//
7957// e.g. in a SMB server connection, if password is changed, connection will be lost, this func will return false
8058func (filesystemAPI ) PathValid (path string ) (bool , error ) {
81- return pathValid (path )
59+ return utils . IsPathValid (path )
8260}
8361
8462// Mkdir makes a dir with `os.MkdirAll`.
0 commit comments