From 1b11233c92eba610ed069162f1e496de92652512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 28 Mar 2022 11:11:50 +0200 Subject: [PATCH] Shaman: more path -> filepath Just more Windows fixes. --- pkg/shaman/checkout/manager.go | 5 ++--- pkg/shaman/cleanup_test.go | 5 ++--- pkg/shaman/filestore/substore_test.go | 6 +++--- pkg/shaman/filestore/testing.go | 3 +-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/shaman/checkout/manager.go b/pkg/shaman/checkout/manager.go index b425c53f..192640ef 100644 --- a/pkg/shaman/checkout/manager.go +++ b/pkg/shaman/checkout/manager.go @@ -27,7 +27,6 @@ import ( "fmt" "math/rand" "os" - "path" "path/filepath" "sync" "time" @@ -175,7 +174,7 @@ func (m *Manager) EraseCheckout(checkoutID string) error { // Try to remove the parent path as well, to not keep the dangling two-letter dirs. // Failure is fine, though, because there is no guarantee it's empty anyway. - os.Remove(path.Dir(checkoutPaths.absolutePath)) + os.Remove(filepath.Dir(checkoutPaths.absolutePath)) logger.Info().Msg("shaman: removed checkout directory") return nil } @@ -210,7 +209,7 @@ func (m *Manager) SymlinkToCheckout(blobPath, checkoutPath, symlinkRelativePath logger.Debug().Msg("shaman: creating parent directory") - dir := path.Dir(symlinkPath) + dir := filepath.Dir(symlinkPath) if err := os.MkdirAll(dir, 0777); err != nil { logger.Error().Err(err).Msg("shaman: unable to create parent directory") return err diff --git a/pkg/shaman/cleanup_test.go b/pkg/shaman/cleanup_test.go index b219018f..2935dc74 100644 --- a/pkg/shaman/cleanup_test.go +++ b/pkg/shaman/cleanup_test.go @@ -24,7 +24,6 @@ package shaman import ( "os" - "path" "path/filepath" "testing" "time" @@ -119,7 +118,7 @@ func TestGCComponents(t *testing.T) { // utility mapping to be able to find absolute paths more easily absPaths := map[string]string{} for absPath := range expectOld { - absPaths[path.Base(absPath)] = absPath + absPaths[filepath.Base(absPath)] = absPath } // No symlinks created yet, so this should report all the files in oldFiles. @@ -195,7 +194,7 @@ func TestGarbageCollect(t *testing.T) { // utility mapping to be able to find absolute paths more easily absPaths := map[string]string{} for absPath := range expectOld { - absPaths[path.Base(absPath)] = absPath + absPaths[filepath.Base(absPath)] = absPath } // Create some symlinks diff --git a/pkg/shaman/filestore/substore_test.go b/pkg/shaman/filestore/substore_test.go index 806e9f93..70b3efe8 100644 --- a/pkg/shaman/filestore/substore_test.go +++ b/pkg/shaman/filestore/substore_test.go @@ -49,9 +49,9 @@ func TestContains(t *testing.T) { assert.True(t, bin.contains("", filepath.FromSlash("/base/testunit/jemoeder.txt"))) assert.True(t, bin.contains("jemoeder", filepath.FromSlash("/base/testunit/jemoeder.txt"))) assert.False(t, bin.contains("jemoeder", filepath.FromSlash("/base/testunit/opjehoofd/jemoeder.txt"))) - assert.False(t, bin.contains("", "/etc/passwd")) - assert.False(t, bin.contains("/", "/etc/passwd")) - assert.False(t, bin.contains("/etc", "/etc/passwd")) + assert.False(t, bin.contains("", filepath.FromSlash("/etc/passwd"))) + assert.False(t, bin.contains(filepath.FromSlash("/"), filepath.FromSlash("/etc/passwd"))) + assert.False(t, bin.contains(filepath.FromSlash("/etc"), filepath.FromSlash("/etc/passwd"))) } func TestFilePermissions(t *testing.T) { diff --git a/pkg/shaman/filestore/testing.go b/pkg/shaman/filestore/testing.go index d525d9e8..efbc77ef 100644 --- a/pkg/shaman/filestore/testing.go +++ b/pkg/shaman/filestore/testing.go @@ -25,7 +25,6 @@ package filestore import ( "io/ioutil" "os" - "path" "path/filepath" "runtime" "time" @@ -80,7 +79,7 @@ func (s *Store) MustStoreFileForTest(checksum string, filesize int64, contents [ // Panics if there are any errors. func LinkTestFileStore(cloneTo string) { _, myFilename, _, _ := runtime.Caller(0) - fileStorePath := filepath.Join(path.Dir(path.Dir(myFilename)), "_test_file_store") + fileStorePath := filepath.Join(filepath.Dir(filepath.Dir(myFilename)), "_test_file_store") now := time.Now() visit := func(visitPath string, info os.FileInfo, err error) error {