Skip to content

Commit ca8cc1b

Browse files
committed
Ensure IsSymlink works on Windows mount point
1 parent 75f6426 commit ca8cc1b

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

pkg/os/filesystem/api.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package filesystem
22

33
import (
4-
"fmt"
54
"os"
65
"path/filepath"
76

@@ -112,23 +111,16 @@ func (filesystemAPI) IsSymlink(tgt string) (bool, error) {
112111
// This code is similar to k8s.io/kubernetes/pkg/util/mount except the pathExists usage.
113112
// Also in a remote call environment the os error cannot be passed directly back, hence the callers
114113
// are expected to perform the isExists check before calling this call in CSI proxy.
115-
stat, err := os.Lstat(tgt)
114+
isSymlink, err := utils.IsPathSymlink(tgt)
116115
if err != nil {
117116
return false, err
118117
}
119118

120-
// If its a link and it points to an existing file then its a mount point.
121-
if stat.Mode()&os.ModeSymlink != 0 {
122-
target, err := os.Readlink(tgt)
123-
if err != nil {
124-
return false, fmt.Errorf("readlink error: %v", err)
125-
}
126-
exists, err := pathExists(target)
127-
if err != nil {
128-
return false, err
129-
}
130-
return exists, nil
119+
// mounted folder created by SetVolumeMountPoint may still report ModeSymlink == 0
120+
mountedFolder, err := utils.IsMountedFolder(tgt)
121+
if err != nil {
122+
return false, err
131123
}
132124

133-
return false, nil
125+
return isSymlink || mountedFolder, nil
134126
}

0 commit comments

Comments
 (0)