1
1
package filesystem
2
2
3
3
import (
4
- "errors"
5
4
"fmt"
6
5
"os"
7
6
"path/filepath"
8
7
9
- "golang.org/x/sys/windows"
10
- "k8s.io/klog/v2"
8
+ "github.com/kubernetes-csi/csi-proxy/pkg/utils"
11
9
)
12
10
13
11
// Implements the Filesystem OS API calls. All code here should be very simple
@@ -50,26 +48,6 @@ func (filesystemAPI) PathExists(path string) (bool, error) {
50
48
return pathExists (path )
51
49
}
52
50
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
-
73
51
// PathValid determines whether all elements of a path exist
74
52
//
75
53
// 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) {
78
56
//
79
57
// e.g. in a SMB server connection, if password is changed, connection will be lost, this func will return false
80
58
func (filesystemAPI ) PathValid (path string ) (bool , error ) {
81
- return pathValid (path )
59
+ return utils . IsPathValid (path )
82
60
}
83
61
84
62
// Mkdir makes a dir with `os.MkdirAll`.
0 commit comments