44 "fmt"
55 "os"
66 "path/filepath"
7- "strings"
87
98 "github.com/kubernetes-csi/csi-proxy/v2/pkg/utils"
109)
@@ -49,17 +48,6 @@ func (filesystemAPI) PathExists(path string) (bool, error) {
4948 return pathExists (path )
5049}
5150
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-
6351// PathValid determines whether all elements of a path exist
6452//
6553// 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) {
6856//
6957// e.g. in a SMB server connection, if password is changed, connection will be lost, this func will return false
7058func (filesystemAPI ) PathValid (path string ) (bool , error ) {
71- return pathValid (path )
59+ return utils . IsPathValid (path )
7260}
7361
7462// Mkdir makes a dir with `os.MkdirAll`.
@@ -124,18 +112,23 @@ func (filesystemAPI) IsSymlink(tgt string) (bool, error) {
124112 // This code is similar to k8s.io/kubernetes/pkg/util/mount except the pathExists usage.
125113 // Also in a remote call environment the os error cannot be passed directly back, hence the callers
126114 // 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 )
128122 if err != nil {
129123 return false , err
130124 }
131125
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 {
134127 target , err := os .Readlink (tgt )
135128 if err != nil {
136129 return false , fmt .Errorf ("readlink error: %v" , err )
137130 }
138- exists , err := pathExists (target )
131+ exists , err := utils . PathExists (target )
139132 if err != nil {
140133 return false , err
141134 }
0 commit comments