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.
This commit is contained in:
Krishnakumar R(KK) 2020-01-30 15:43:21 -08:00
parent 8be2f8c626
commit 72fe307b35
2 changed files with 4 additions and 5 deletions

View File

@ -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) {

View File

@ -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))