From 72fe307b35f5aa79ae62b47d090ecc5c780995da Mon Sep 17 00:00:00 2001 From: "Krishnakumar R(KK)" <29471693+kkmsft@users.noreply.github.com> Date: Thu, 30 Jan 2020 15:43:21 -0800 Subject: [PATCH] Move 'path' package usage to 'path/filepath'. In case of windows, the path package functions such as 'Dir' returns faulty directory path. For eg: 'path.Dir' on 'c:\var\lib\kubelet\pods' returns '.', where as the result should have been 'c:\var\lib\kubelet'. The filepath package returns the right values. --- pkg/volume/csi/csi_mounter.go | 3 +-- pkg/volume/csi/csi_plugin.go | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/volume/csi/csi_mounter.go b/pkg/volume/csi/csi_mounter.go index a5e1254ff2a..c9d831bdf57 100644 --- a/pkg/volume/csi/csi_mounter.go +++ b/pkg/volume/csi/csi_mounter.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "os" - "path" "path/filepath" "strconv" @@ -432,7 +431,7 @@ func removeMountDir(plug *csiPlugin, mountPath string) error { return errors.New(log("failed to remove dir [%s]: %v", mountPath, err)) } // remove volume data file as well - volPath := path.Dir(mountPath) + volPath := filepath.Dir(mountPath) dataFile := filepath.Join(volPath, volDataFileName) klog.V(4).Info(log("also deleting volume info data file [%s]", dataFile)) if err := os.Remove(dataFile); err != nil && !os.IsNotExist(err) { diff --git a/pkg/volume/csi/csi_plugin.go b/pkg/volume/csi/csi_plugin.go index fa335a07fc1..7f19d83223d 100644 --- a/pkg/volume/csi/csi_plugin.go +++ b/pkg/volume/csi/csi_plugin.go @@ -20,7 +20,7 @@ import ( "errors" "fmt" "os" - "path" + "path/filepath" "strings" "time" @@ -387,7 +387,7 @@ func (p *csiPlugin) NewMounter( // Save volume info in pod dir dir := mounter.GetPath() - dataDir := path.Dir(dir) // dropoff /mount at end + dataDir := filepath.Dir(dir) // dropoff /mount at end if err := os.MkdirAll(dataDir, 0750); err != nil { return nil, errors.New(log("failed to create dir %#v: %v", dataDir, err)) @@ -438,7 +438,7 @@ func (p *csiPlugin) NewUnmounter(specName string, podUID types.UID) (volume.Unmo // load volume info from file dir := unmounter.GetPath() - dataDir := path.Dir(dir) // dropoff /mount at end + dataDir := filepath.Dir(dir) // dropoff /mount at end data, err := loadVolumeData(dataDir, volDataFileName) if err != nil { return nil, errors.New(log("unmounter failed to load volume data file [%s]: %v", dir, err))