11package filesystem
22
33import (
4- // "fmt"
4+ "fmt"
55 "os"
6- // "os/exec"
7- // "runtime"
86)
97
108// Implements the Filesystem OS API calls. All code here should be very simple
@@ -18,7 +16,7 @@ func New() APIImplementor {
1816 return APIImplementor {}
1917}
2018
21- func ( APIImplementor ) PathExists (path string ) (bool , error ) {
19+ func pathExists (path string ) (bool , error ) {
2220 _ , err := os .Stat (path )
2321 if err == nil {
2422 return true , nil
@@ -29,6 +27,10 @@ func (APIImplementor) PathExists(path string) (bool, error) {
2927 return false , err
3028}
3129
30+ func (APIImplementor ) PathExists (path string ) (bool , error ) {
31+ return pathExists (path )
32+ }
33+
3234func (APIImplementor ) Mkdir (path string ) error {
3335 return os .MkdirAll (path , 0755 )
3436}
@@ -43,3 +45,33 @@ func (APIImplementor) Rmdir(path string, force bool) error {
4345func (APIImplementor ) LinkPath (tgt string , src string ) error {
4446 return os .Symlink (tgt , src )
4547}
48+
49+ // IsMountPoint - returns true if its a mount point.
50+ // A path is considered a mount point if:
51+ // - directory exists and
52+ // - it is a soft link and
53+ // - the target path of the link exists.
54+ func (APIImplementor ) IsMountPoint (tgt string ) (bool , error ) {
55+ // This code is similar to k8s.io/kubernetes/pkg/util/mount except the pathExists usage.
56+ // Also in a remote call environment the os error cannot be passed directly back, hence the callers
57+ // are expected to perform the isExists check before calling this call in CSI proxy.
58+ stat , err := os .Lstat (tgt )
59+ if err != nil {
60+ return false , err
61+ }
62+
63+ // If its a link and it points to an existing file then its a mount point.
64+ if stat .Mode ()& os .ModeSymlink != 0 {
65+ target , err := os .Readlink (tgt )
66+ if err != nil {
67+ return false , fmt .Errorf ("readlink error: %v" , err )
68+ }
69+ exists , err := pathExists (target )
70+ if err != nil {
71+ return false , err
72+ }
73+ return exists , nil
74+ }
75+
76+ return false , nil
77+ }
0 commit comments