Always use filepath.Join instead of path.Join
This patch cleans up pkg/util/mount/* and pkg/util/volume/* to always use filepath.Join instead of path.Join. filepath.Join is preferred because path.Join can have issues on Windows.
This commit is contained in:
@@ -27,7 +27,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -80,7 +80,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
|
||||
// https://github.com/torvalds/linux/blob/master/drivers/block/rbd.c
|
||||
name := f.Name()
|
||||
// First match pool, then match name.
|
||||
poolFile := path.Join(sys_path, name, "pool")
|
||||
poolFile := filepath.Join(sys_path, name, "pool")
|
||||
poolBytes, err := ioutil.ReadFile(poolFile)
|
||||
if err != nil {
|
||||
klog.V(4).Infof("error reading %s: %v", poolFile, err)
|
||||
@@ -90,7 +90,7 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) {
|
||||
klog.V(4).Infof("device %s is not %q: %q", name, pool, string(poolBytes))
|
||||
continue
|
||||
}
|
||||
imgFile := path.Join(sys_path, name, "name")
|
||||
imgFile := filepath.Join(sys_path, name, "name")
|
||||
imgBytes, err := ioutil.ReadFile(imgFile)
|
||||
if err != nil {
|
||||
klog.V(4).Infof("error reading %s: %v", imgFile, err)
|
||||
@@ -160,12 +160,12 @@ func getNbdDevFromImageAndPool(pool string, image string) (string, bool) {
|
||||
klog.V(4).Infof("error reading nbd info directory %s: %v", nbdPath, err)
|
||||
continue
|
||||
}
|
||||
pidBytes, err := ioutil.ReadFile(path.Join(nbdPath, "pid"))
|
||||
pidBytes, err := ioutil.ReadFile(filepath.Join(nbdPath, "pid"))
|
||||
if err != nil {
|
||||
klog.V(5).Infof("did not find valid pid file in dir %s: %v", nbdPath, err)
|
||||
continue
|
||||
}
|
||||
cmdlineFileName := path.Join("/proc", strings.TrimSpace(string(pidBytes)), "cmdline")
|
||||
cmdlineFileName := filepath.Join("/proc", strings.TrimSpace(string(pidBytes)), "cmdline")
|
||||
rawCmdline, err := ioutil.ReadFile(cmdlineFileName)
|
||||
if err != nil {
|
||||
klog.V(4).Infof("failed to read cmdline file %s: %v", cmdlineFileName, err)
|
||||
@@ -186,7 +186,7 @@ func getNbdDevFromImageAndPool(pool string, image string) (string, bool) {
|
||||
nbdPath, imgPath, cmdlineArgs[2])
|
||||
continue
|
||||
}
|
||||
devicePath := path.Join("/dev", "nbd"+strconv.Itoa(i))
|
||||
devicePath := filepath.Join("/dev", "nbd"+strconv.Itoa(i))
|
||||
if _, err := os.Lstat(devicePath); err != nil {
|
||||
klog.Warningf("Stat device %s for imgpath %s failed %v", devicePath, imgPath, err)
|
||||
continue
|
||||
@@ -248,7 +248,7 @@ func checkRbdNbdTools(e mount.Exec) bool {
|
||||
// Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/mounts/pool-image-image.
|
||||
func makePDNameInternal(host volume.VolumeHost, pool string, image string) string {
|
||||
// Backward compatibility for the deprecated format: /var/lib/kubelet/plugins/kubernetes.io/rbd/rbd/pool-image-image.
|
||||
deprecatedDir := path.Join(host.GetPluginDir(rbdPluginName), "rbd", pool+"-image-"+image)
|
||||
deprecatedDir := filepath.Join(host.GetPluginDir(rbdPluginName), "rbd", pool+"-image-"+image)
|
||||
info, err := os.Stat(deprecatedDir)
|
||||
if err == nil && info.IsDir() {
|
||||
// The device mount path has already been created with the deprecated format, return it.
|
||||
@@ -256,12 +256,12 @@ func makePDNameInternal(host volume.VolumeHost, pool string, image string) strin
|
||||
return deprecatedDir
|
||||
}
|
||||
// Return the canonical format path.
|
||||
return path.Join(host.GetPluginDir(rbdPluginName), volutil.MountsInGlobalPDPath, pool+"-image-"+image)
|
||||
return filepath.Join(host.GetPluginDir(rbdPluginName), volutil.MountsInGlobalPDPath, pool+"-image-"+image)
|
||||
}
|
||||
|
||||
// Make a directory like /var/lib/kubelet/plugins/kubernetes.io/rbd/volumeDevices/pool-image-image.
|
||||
func makeVDPDNameInternal(host volume.VolumeHost, pool string, image string) string {
|
||||
return path.Join(host.GetVolumeDevicePluginDir(rbdPluginName), pool+"-image-"+image)
|
||||
return filepath.Join(host.GetVolumeDevicePluginDir(rbdPluginName), pool+"-image-"+image)
|
||||
}
|
||||
|
||||
// RBDUtil implements diskManager interface.
|
||||
@@ -486,7 +486,7 @@ func (util *RBDUtil) DetachDisk(plugin *rbdPlugin, deviceMountPath string, devic
|
||||
|
||||
// Currently, we don't persist rbd info on the disk, but for backward
|
||||
// compatbility, we need to clean it if found.
|
||||
rbdFile := path.Join(deviceMountPath, "rbd.json")
|
||||
rbdFile := filepath.Join(deviceMountPath, "rbd.json")
|
||||
exists, err := utilpath.Exists(utilpath.CheckFollowSymlink, rbdFile)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user