From c65d9e4d59fb3f332114c29db10c5ba2b13538db Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Wed, 15 Jun 2022 15:17:24 +0300 Subject: [PATCH] Replaces path.Operation with filepath.Operation The path module has a few different functions: Clean, Split, Join, Ext, Dir, Base, IsAbs. These functions do not take into account the OS-specific path separator, meaning that they won't behave as intended on Windows. For example, Dir is supposed to return all but the last element of the path. For the path "C:\some\dir\somewhere", it is supposed to return "C:\some\dir\", however, it returns ".". Instead of these functions, the ones in filepath should be used instead. --- pkg/util/removeall/removeall_test.go | 9 ++++----- pkg/volume/util/hostutil/hostutil_windows.go | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/util/removeall/removeall_test.go b/pkg/util/removeall/removeall_test.go index bb5acc1c521..98b0dfe0f1d 100644 --- a/pkg/util/removeall/removeall_test.go +++ b/pkg/util/removeall/removeall_test.go @@ -19,7 +19,6 @@ package removeall import ( "errors" "os" - "path" "path/filepath" "strings" "testing" @@ -117,11 +116,11 @@ func TestRemoveAllOneFilesystem(t *testing.T) { for _, item := range test.items { if strings.HasSuffix(item, "/") { item = strings.TrimRight(item, "/") - if err = os.Mkdir(path.Join(tmpDir, item), 0777); err != nil { + if err = os.Mkdir(filepath.Join(tmpDir, item), 0777); err != nil { t.Fatalf("error creating %s: %v", item, err) } } else { - f, err := os.Create(path.Join(tmpDir, item)) + f, err := os.Create(filepath.Join(tmpDir, item)) if err != nil { t.Fatalf("error creating %s: %v", item, err) } @@ -237,11 +236,11 @@ func TestRemoveDirsOneFilesystem(t *testing.T) { for _, item := range test.items { if strings.HasSuffix(item, "/") { item = strings.TrimRight(item, "/") - if err = os.Mkdir(path.Join(tmpDir, item), 0777); err != nil { + if err = os.Mkdir(filepath.Join(tmpDir, item), 0777); err != nil { t.Fatalf("error creating %s: %v", item, err) } } else { - f, err := os.Create(path.Join(tmpDir, item)) + f, err := os.Create(filepath.Join(tmpDir, item)) if err != nil { t.Fatalf("error creating %s: %v", item, err) } diff --git a/pkg/volume/util/hostutil/hostutil_windows.go b/pkg/volume/util/hostutil/hostutil_windows.go index 51ad0344a13..c8f35a1737c 100644 --- a/pkg/volume/util/hostutil/hostutil_windows.go +++ b/pkg/volume/util/hostutil/hostutil_windows.go @@ -23,7 +23,6 @@ import ( "fmt" "io/fs" "os" - "path" "path/filepath" "strings" "syscall" @@ -72,7 +71,7 @@ func getDeviceNameFromMount(mounter mount.Interface, mountPath, pluginMountDir s } } - return path.Base(mountPath), nil + return filepath.Base(mountPath), nil } // DeviceOpened determines if the device is in use elsewhere