Skip to content

Commit 72fe307

Browse files
committed
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.
1 parent 8be2f8c commit 72fe307

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

pkg/volume/csi/csi_mounter.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"os"
25-
"path"
2625
"path/filepath"
2726
"strconv"
2827

@@ -432,7 +431,7 @@ func removeMountDir(plug *csiPlugin, mountPath string) error {
432431
return errors.New(log("failed to remove dir [%s]: %v", mountPath, err))
433432
}
434433
// remove volume data file as well
435-
volPath := path.Dir(mountPath)
434+
volPath := filepath.Dir(mountPath)
436435
dataFile := filepath.Join(volPath, volDataFileName)
437436
klog.V(4).Info(log("also deleting volume info data file [%s]", dataFile))
438437
if err := os.Remove(dataFile); err != nil && !os.IsNotExist(err) {

pkg/volume/csi/csi_plugin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"errors"
2121
"fmt"
2222
"os"
23-
"path"
23+
"path/filepath"
2424
"strings"
2525
"time"
2626

@@ -387,7 +387,7 @@ func (p *csiPlugin) NewMounter(
387387

388388
// Save volume info in pod dir
389389
dir := mounter.GetPath()
390-
dataDir := path.Dir(dir) // dropoff /mount at end
390+
dataDir := filepath.Dir(dir) // dropoff /mount at end
391391

392392
if err := os.MkdirAll(dataDir, 0750); err != nil {
393393
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
438438

439439
// load volume info from file
440440
dir := unmounter.GetPath()
441-
dataDir := path.Dir(dir) // dropoff /mount at end
441+
dataDir := filepath.Dir(dir) // dropoff /mount at end
442442
data, err := loadVolumeData(dataDir, volDataFileName)
443443
if err != nil {
444444
return nil, errors.New(log("unmounter failed to load volume data file [%s]: %v", dir, err))

0 commit comments

Comments
 (0)