4
4
"fmt"
5
5
"os"
6
6
"path/filepath"
7
- "strings"
8
7
9
8
"github.com/kubernetes-csi/csi-proxy/v2/pkg/utils"
10
9
)
@@ -49,17 +48,6 @@ func (filesystemAPI) PathExists(path string) (bool, error) {
49
48
return pathExists (path )
50
49
}
51
50
52
- func pathValid (path string ) (bool , error ) {
53
- cmd := `Test-Path $Env:remotepath`
54
- cmdEnv := fmt .Sprintf ("remotepath=%s" , path )
55
- output , err := utils .RunPowershellCmd (cmd , cmdEnv )
56
- if err != nil {
57
- return false , fmt .Errorf ("returned output: %s, error: %v" , string (output ), err )
58
- }
59
-
60
- return strings .HasPrefix (strings .ToLower (string (output )), "true" ), nil
61
- }
62
-
63
51
// PathValid determines whether all elements of a path exist
64
52
//
65
53
// https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-path?view=powershell-7
@@ -68,7 +56,7 @@ func pathValid(path string) (bool, error) {
68
56
//
69
57
// e.g. in a SMB server connection, if password is changed, connection will be lost, this func will return false
70
58
func (filesystemAPI ) PathValid (path string ) (bool , error ) {
71
- return pathValid (path )
59
+ return utils . IsPathValid (path )
72
60
}
73
61
74
62
// Mkdir makes a dir with `os.MkdirAll`.
@@ -124,18 +112,23 @@ func (filesystemAPI) IsSymlink(tgt string) (bool, error) {
124
112
// This code is similar to k8s.io/kubernetes/pkg/util/mount except the pathExists usage.
125
113
// Also in a remote call environment the os error cannot be passed directly back, hence the callers
126
114
// are expected to perform the isExists check before calling this call in CSI proxy.
127
- stat , err := os .Lstat (tgt )
115
+ isSymlink , err := utils .IsPathSymlink (tgt )
116
+ if err != nil {
117
+ return false , err
118
+ }
119
+
120
+ // mounted folder created by SetVolumeMountPoint may still report ModeSymlink == 0
121
+ mountedFolder , err := utils .IsMountedFolder (tgt )
128
122
if err != nil {
129
123
return false , err
130
124
}
131
125
132
- // If its a link and it points to an existing file then its a mount point.
133
- if stat .Mode ()& os .ModeSymlink != 0 {
126
+ if isSymlink || mountedFolder {
134
127
target , err := os .Readlink (tgt )
135
128
if err != nil {
136
129
return false , fmt .Errorf ("readlink error: %v" , err )
137
130
}
138
- exists , err := pathExists (target )
131
+ exists , err := utils . PathExists (target )
139
132
if err != nil {
140
133
return false , err
141
134
}
0 commit comments