Skip to content

Commit 9755e88

Browse files
authored
Merge pull request #393 from laozc/wmi-process-smb-api
fix: Ensure IsSymlink works on Windows mounted folder
2 parents 26a2a26 + 3c06f01 commit 9755e88

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

pkg/os/filesystem/api.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,8 @@ func New() API {
3333
return filesystemAPI{}
3434
}
3535

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-
4736
func (filesystemAPI) PathExists(path string) (bool, error) {
48-
return pathExists(path)
37+
return utils.PathExists(path)
4938
}
5039

5140
// PathValid determines whether all elements of a path exist
@@ -112,18 +101,23 @@ func (filesystemAPI) IsSymlink(tgt string) (bool, error) {
112101
// This code is similar to k8s.io/kubernetes/pkg/util/mount except the pathExists usage.
113102
// Also in a remote call environment the os error cannot be passed directly back, hence the callers
114103
// 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)
116111
if err != nil {
117112
return false, err
118113
}
119114

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 {
122116
target, err := os.Readlink(tgt)
123117
if err != nil {
124118
return false, fmt.Errorf("readlink error: %v", err)
125119
}
126-
exists, err := pathExists(target)
120+
exists, err := utils.PathExists(target)
127121
if err != nil {
128122
return false, err
129123
}

pkg/utils/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,15 @@ func CreateSymlink(link, target string, isDir bool) error {
109109
)
110110
return err
111111
}
112+
113+
// PathExists checks whether the given `path` exists.
114+
func PathExists(path string) (bool, error) {
115+
_, err := os.Lstat(path)
116+
if err == nil {
117+
return true, nil
118+
}
119+
if os.IsNotExist(err) {
120+
return false, nil
121+
}
122+
return false, err
123+
}

0 commit comments

Comments
 (0)