@@ -33,19 +33,8 @@ func New() API {
33
33
return filesystemAPI {}
34
34
}
35
35
36
- func pathExists (path string ) (bool , error ) {
37
- _ , err := os .Lstat (path )
38
- if err == nil {
39
- return true , nil
40
- }
41
- if os .IsNotExist (err ) {
42
- return false , nil
43
- }
44
- return false , err
45
- }
46
-
47
36
func (filesystemAPI ) PathExists (path string ) (bool , error ) {
48
- return pathExists (path )
37
+ return utils . PathExists (path )
49
38
}
50
39
51
40
// PathValid determines whether all elements of a path exist
@@ -112,18 +101,23 @@ func (filesystemAPI) IsSymlink(tgt string) (bool, error) {
112
101
// This code is similar to k8s.io/kubernetes/pkg/util/mount except the pathExists usage.
113
102
// Also in a remote call environment the os error cannot be passed directly back, hence the callers
114
103
// are expected to perform the isExists check before calling this call in CSI proxy.
115
- stat , err := os .Lstat (tgt )
104
+ isSymlink , err := utils .IsPathSymlink (tgt )
105
+ if err != nil {
106
+ return false , err
107
+ }
108
+
109
+ // mounted folder created by SetVolumeMountPoint may still report ModeSymlink == 0
110
+ mountedFolder , err := utils .IsMountedFolder (tgt )
116
111
if err != nil {
117
112
return false , err
118
113
}
119
114
120
- // If its a link and it points to an existing file then its a mount point.
121
- if stat .Mode ()& os .ModeSymlink != 0 {
115
+ if isSymlink || mountedFolder {
122
116
target , err := os .Readlink (tgt )
123
117
if err != nil {
124
118
return false , fmt .Errorf ("readlink error: %v" , err )
125
119
}
126
- exists , err := pathExists (target )
120
+ exists , err := utils . PathExists (target )
127
121
if err != nil {
128
122
return false , err
129
123
}
0 commit comments