diff options
65 files changed, 186 insertions, 205 deletions
diff --git a/cmd/gitaly-git2go/merge_test.go b/cmd/gitaly-git2go/merge_test.go index f0068a7a1..c16dbd8af 100644 --- a/cmd/gitaly-git2go/merge_test.go +++ b/cmd/gitaly-git2go/merge_test.go @@ -5,7 +5,7 @@ package main import ( "bytes" "os/exec" - "path" + "path/filepath" "strings" "testing" "time" @@ -40,7 +40,7 @@ func merge(t *testing.T, opts mergeSubcommand) (string, string, error) { args = append(args, arg, value) } - binary := path.Join(config.Config.BinDir, "gitaly-git2go") + binary := filepath.Join(config.Config.BinDir, "gitaly-git2go") ctx, cancel := testhelper.Context() defer cancel() diff --git a/cmd/gitaly-ssh/auth_test.go b/cmd/gitaly-ssh/auth_test.go index dac58658e..30d7e41a7 100644 --- a/cmd/gitaly-ssh/auth_test.go +++ b/cmd/gitaly-ssh/auth_test.go @@ -5,7 +5,7 @@ import ( "net" "os" "os/exec" - "path" + "path/filepath" "strconv" "strings" "testing" @@ -31,7 +31,7 @@ func TestConnectivity(t *testing.T) { cwd, err := os.Getwd() require.NoError(t, err) - certPoolPath := path.Join(cwd, "testdata/certs") + certPoolPath := filepath.Join(cwd, "testdata", "certs") testRepo := testhelper.TestRepository() diff --git a/cmd/gitaly-ssh/testhelper_test.go b/cmd/gitaly-ssh/testhelper_test.go index 4e823925a..729ff1f59 100644 --- a/cmd/gitaly-ssh/testhelper_test.go +++ b/cmd/gitaly-ssh/testhelper_test.go @@ -2,7 +2,7 @@ package main import ( "os" - "path" + "path/filepath" "testing" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" @@ -20,7 +20,7 @@ func testMain(m *testing.M) int { defer testhelper.MustHaveNoChildProcess() testhelper.ConfigureGitalySSH() - gitalySSHPath = path.Join(config.Config.BinDir, "gitaly-ssh") + gitalySSHPath = filepath.Join(config.Config.BinDir, "gitaly-ssh") return m.Run() } diff --git a/cmd/gitaly-wrapper/main.go b/cmd/gitaly-wrapper/main.go index 20d491058..e31c9e2e0 100644 --- a/cmd/gitaly-wrapper/main.go +++ b/cmd/gitaly-wrapper/main.go @@ -6,7 +6,7 @@ import ( "os" "os/exec" "os/signal" - "path" + "path/filepath" "strconv" "syscall" "time" @@ -152,7 +152,7 @@ func isGitaly(p *os.Process, gitalyBin string) bool { return false } - if path.Base(command) == path.Base(gitalyBin) { + if filepath.Base(command) == filepath.Base(gitalyBin) { return true } diff --git a/internal/bootstrap/bootstrap_test.go b/internal/bootstrap/bootstrap_test.go index 23c49209b..36be95673 100644 --- a/internal/bootstrap/bootstrap_test.go +++ b/internal/bootstrap/bootstrap_test.go @@ -7,7 +7,7 @@ import ( "net" "net/http" "os" - "path" + "path/filepath" "strconv" "syscall" "testing" @@ -59,7 +59,7 @@ func (s *testServer) slowRequest(duration time.Duration) <-chan error { } func TestCreateUnixListener(t *testing.T) { - socketPath := path.Join(os.TempDir(), "gitaly-test-unix-socket") + socketPath := filepath.Join(os.TempDir(), "gitaly-test-unix-socket") if err := os.Remove(socketPath); err != nil { require.True(t, os.IsNotExist(err), "cannot delete dangling socket: %v", err) } @@ -290,7 +290,7 @@ func makeBootstrap(t *testing.T) (*Bootstrap, *testServer) { for network, address := range map[string]string{ "tcp": "127.0.0.1:0", - "unix": path.Join(os.TempDir(), "gitaly-test-unix-socket"), + "unix": filepath.Join(os.TempDir(), "gitaly-test-unix-socket"), } { b.RegisterStarter(start(network, address)) } diff --git a/internal/git/alternates/alternates.go b/internal/git/alternates/alternates.go index 29ba66b8f..b17fdaff3 100644 --- a/internal/git/alternates/alternates.go +++ b/internal/git/alternates/alternates.go @@ -2,7 +2,7 @@ package alternates import ( "fmt" - "path" + "path/filepath" "strings" "gitlab.com/gitlab-org/gitaly/internal/git/repository" @@ -20,14 +20,14 @@ func PathAndEnv(repo repository.GitRepo) (string, []string, error) { var env []string if dir := repo.GetGitObjectDirectory(); dir != "" { - env = append(env, fmt.Sprintf("GIT_OBJECT_DIRECTORY=%s", path.Join(repoPath, dir))) + env = append(env, fmt.Sprintf("GIT_OBJECT_DIRECTORY=%s", filepath.Join(repoPath, dir))) } if dirs := repo.GetGitAlternateObjectDirectories(); len(dirs) > 0 { var dirsList []string for _, dir := range dirs { - dirsList = append(dirsList, path.Join(repoPath, dir)) + dirsList = append(dirsList, filepath.Join(repoPath, dir)) } env = append(env, fmt.Sprintf("GIT_ALTERNATE_OBJECT_DIRECTORIES=%s", strings.Join(dirsList, ":"))) diff --git a/internal/git/hooks/hooks.go b/internal/git/hooks/hooks.go index 88e75fce2..aabb2f5fa 100644 --- a/internal/git/hooks/hooks.go +++ b/internal/git/hooks/hooks.go @@ -2,7 +2,7 @@ package hooks import ( "fmt" - "path" + "path/filepath" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" ) @@ -23,7 +23,7 @@ func Path() string { return "/var/empty" } - return path.Join(config.Config.Ruby.Dir, "git-hooks") + return filepath.Join(config.Config.Ruby.Dir, "git-hooks") } // GitPushOptions turns a slice of git push option values into a GIT_PUSH_OPTION_COUNT and individual diff --git a/internal/git/objectpool/clone.go b/internal/git/objectpool/clone.go index 066deb5a4..e21587de8 100644 --- a/internal/git/objectpool/clone.go +++ b/internal/git/objectpool/clone.go @@ -3,7 +3,7 @@ package objectpool import ( "context" "os" - "path" + "path/filepath" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -37,5 +37,5 @@ func (o *ObjectPool) clone(ctx context.Context, repo *gitalypb.Repository) error } func (o *ObjectPool) removeHooksDir() error { - return os.RemoveAll(path.Join(o.FullPath(), "hooks")) + return os.RemoveAll(filepath.Join(o.FullPath(), "hooks")) } diff --git a/internal/git/objectpool/clone_test.go b/internal/git/objectpool/clone_test.go index 20b38689b..cb10fd01d 100644 --- a/internal/git/objectpool/clone_test.go +++ b/internal/git/objectpool/clone_test.go @@ -1,7 +1,7 @@ package objectpool import ( - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -24,7 +24,7 @@ func TestClone(t *testing.T) { defer pool.Remove(ctx) require.DirExists(t, pool.FullPath()) - require.DirExists(t, path.Join(pool.FullPath(), "objects")) + require.DirExists(t, filepath.Join(pool.FullPath(), "objects")) } func TestCloneExistingPool(t *testing.T) { diff --git a/internal/git/objectpool/pool_test.go b/internal/git/objectpool/pool_test.go index e7bd963bf..2a2dd2c54 100644 --- a/internal/git/objectpool/pool_test.go +++ b/internal/git/objectpool/pool_test.go @@ -3,7 +3,6 @@ package objectpool import ( "io/ioutil" "os" - "path" "path/filepath" "strings" "testing" @@ -112,7 +111,7 @@ func TestCreate(t *testing.T) { require.True(t, pool.IsValid()) // No hooks - _, err = os.Stat(path.Join(pool.FullPath(), "hooks")) + _, err = os.Stat(filepath.Join(pool.FullPath(), "hooks")) assert.True(t, os.IsNotExist(err)) // origin is set diff --git a/internal/gitaly/config/config_test.go b/internal/gitaly/config/config_test.go index bede1123e..926b6812f 100644 --- a/internal/gitaly/config/config_test.go +++ b/internal/gitaly/config/config_test.go @@ -8,7 +8,6 @@ import ( "io/ioutil" "os" "os/exec" - "path" "path/filepath" "strings" "testing" @@ -235,7 +234,7 @@ func TestValidateStorages(t *testing.T) { repositories2, err := filepath.Abs("testdata/repositories2") require.NoError(t, err) - invalidDir := path.Join(repositories, t.Name()) + invalidDir := filepath.Join(repositories, t.Name()) testCases := []struct { desc string @@ -520,8 +519,8 @@ func TestValidateShellPath(t *testing.T) { tmpDir, err := ioutil.TempDir("", "gitaly-tests-") require.NoError(t, err) - require.NoError(t, os.MkdirAll(path.Join(tmpDir, "bin"), 0755)) - tmpFile := path.Join(tmpDir, "my-file") + require.NoError(t, os.MkdirAll(filepath.Join(tmpDir, "bin"), 0755)) + tmpFile := filepath.Join(tmpDir, "my-file") defer os.RemoveAll(tmpDir) fp, err := os.Create(tmpFile) require.NoError(t, err) @@ -575,7 +574,7 @@ func TestConfigureRuby(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(tmpDir) - tmpFile := path.Join(tmpDir, "file") + tmpFile := filepath.Join(tmpDir, "file") require.NoError(t, ioutil.WriteFile(tmpFile, nil, 0644)) testCases := []struct { diff --git a/internal/gitaly/config/locator.go b/internal/gitaly/config/locator.go index ff8c1a67c..b280a6cfb 100644 --- a/internal/gitaly/config/locator.go +++ b/internal/gitaly/config/locator.go @@ -2,7 +2,7 @@ package config import ( "os" - "path" + "path/filepath" "gitlab.com/gitlab-org/gitaly/internal/git/repository" "gitlab.com/gitlab-org/gitaly/internal/storage" @@ -65,7 +65,7 @@ func (l *configLocator) GetPath(repo repository.GitRepo) (string, error) { return "", status.Errorf(codes.InvalidArgument, "GetRepoPath: %s", err) } - return path.Join(storagePath, relativePath), nil + return filepath.Join(storagePath, relativePath), nil } // GetStorageByName will return the path for the storage, which is fetched by @@ -98,7 +98,7 @@ func (l *configLocator) GetObjectDirectoryPath(repo repository.GitRepo) (string, return "", status.Errorf(codes.InvalidArgument, "GetObjectDirectoryPath: %s", err) } - fullPath := path.Join(repoPath, objectDirectoryPath) + fullPath := filepath.Join(repoPath, objectDirectoryPath) if _, err := os.Stat(fullPath); os.IsNotExist(err) { return "", status.Errorf(codes.NotFound, "GetObjectDirectoryPath: does not exist: %q", fullPath) } diff --git a/internal/gitaly/rubyserver/rubyserver.go b/internal/gitaly/rubyserver/rubyserver.go index 27a02edff..3d5db50ac 100644 --- a/internal/gitaly/rubyserver/rubyserver.go +++ b/internal/gitaly/rubyserver/rubyserver.go @@ -5,7 +5,6 @@ import ( "fmt" "net" "os" - "path" "path/filepath" "strconv" "sync" @@ -117,7 +116,7 @@ func (s *Server) start() error { env = append(env, "SENTRY_ENVIRONMENT="+sentryEnvironment) } - gitalyRuby := path.Join(cfg.Ruby.Dir, "bin", "gitaly-ruby") + gitalyRuby := filepath.Join(cfg.Ruby.Dir, "bin", "gitaly-ruby") numWorkers := cfg.Ruby.NumWorkers balancer.ConfigureBuilder(numWorkers, 0) diff --git a/internal/gitaly/service/blob/get_blobs_test.go b/internal/gitaly/service/blob/get_blobs_test.go index f6a52a5f3..308be3879 100644 --- a/internal/gitaly/service/blob/get_blobs_test.go +++ b/internal/gitaly/service/blob/get_blobs_test.go @@ -3,7 +3,7 @@ package blob import ( "fmt" "io" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -117,7 +117,7 @@ func TestSuccessfulGetBlobsRequest(t *testing.T) { expectedBlob := expectedBlobs[i] expectedBlob.Revision = revision if !expectedBlob.IsSubmodule && expectedBlob.Type == gitalypb.ObjectType_BLOB { - expectedBlob.Data = testhelper.MustReadFile(t, path.Join(testRepoPath, "blobs-sandbox", string(expectedBlob.Path))) + expectedBlob.Data = testhelper.MustReadFile(t, filepath.Join(testRepoPath, "blobs-sandbox", string(expectedBlob.Path))) } if limit == 0 { expectedBlob.Data = nil diff --git a/internal/gitaly/service/commit/tree_entries_test.go b/internal/gitaly/service/commit/tree_entries_test.go index 57a03020f..b3491d832 100644 --- a/internal/gitaly/service/commit/tree_entries_test.go +++ b/internal/gitaly/service/commit/tree_entries_test.go @@ -4,7 +4,7 @@ import ( "fmt" "io" "os" - "path" + "path/filepath" "strings" "testing" @@ -27,14 +27,14 @@ func TestSuccessfulGetTreeEntriesWithCurlyBraces(t *testing.T) { normalFolderName := "issue-46261/folder" curlyFolderName := "issue-46261/{{curly}}" - normalFolder := path.Join(testRepoPath, normalFolderName) - curlyFolder := path.Join(testRepoPath, curlyFolderName) + normalFolder := filepath.Join(testRepoPath, normalFolderName) + curlyFolder := filepath.Join(testRepoPath, curlyFolderName) os.MkdirAll(normalFolder, 0755) os.MkdirAll(curlyFolder, 0755) - testhelper.MustRunCommand(t, nil, "touch", path.Join(normalFolder, "/test1.txt")) - testhelper.MustRunCommand(t, nil, "touch", path.Join(curlyFolder, "/test2.txt")) + testhelper.MustRunCommand(t, nil, "touch", filepath.Join(normalFolder, "/test1.txt")) + testhelper.MustRunCommand(t, nil, "touch", filepath.Join(curlyFolder, "/test2.txt")) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "add", "--all") testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "commit", "-m", "Test commit") @@ -421,10 +421,10 @@ func TestSuccessfulGetTreeEntries_FlatPathMaxDeep_SingleFoldersStructure(t *test folderName := "1/2/3/4/5/6/7/8/9/10/11/12" require.GreaterOrEqual(t, strings.Count(strings.Trim(folderName, "/"), "/"), defaultFlatTreeRecursion, "sanity check: construct folder deeper than default recursion value") - nestedFolder := path.Join(testRepoPath, folderName) + nestedFolder := filepath.Join(testRepoPath, folderName) require.NoError(t, os.MkdirAll(nestedFolder, 0755)) // put single file into the deepest directory - testhelper.MustRunCommand(t, nil, "touch", path.Join(nestedFolder, ".gitkeep")) + testhelper.MustRunCommand(t, nil, "touch", filepath.Join(nestedFolder, ".gitkeep")) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "add", "--all") testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "commit", "-m", "Deep folder struct") diff --git a/internal/gitaly/service/commit/tree_entry.go b/internal/gitaly/service/commit/tree_entry.go index 36a25c8da..10f5b0c4a 100644 --- a/internal/gitaly/service/commit/tree_entry.go +++ b/internal/gitaly/service/commit/tree_entry.go @@ -108,8 +108,8 @@ func (s *server) TreeEntry(in *gitalypb.TreeEntryRequest, stream gitalypb.Commit } requestPath := string(in.GetPath()) - // path.Dir("api/docs") => "api" Correct! - // path.Dir("api/docs/") => "api/docs" WRONG! + // filepath.Dir("api/docs") => "api" Correct! + // filepath.Dir("api/docs/") => "api/docs" WRONG! if len(requestPath) > 1 { requestPath = strings.TrimRight(requestPath, "/") } diff --git a/internal/gitaly/service/commit/util.go b/internal/gitaly/service/commit/util.go index ff4695f1e..ce99e3e58 100644 --- a/internal/gitaly/service/commit/util.go +++ b/internal/gitaly/service/commit/util.go @@ -2,7 +2,7 @@ package commit import ( "fmt" - "path" + "path/filepath" "strconv" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -32,7 +32,7 @@ func newTreeEntry(commitOid, rootOid, rootPath string, filename, oidBytes, modeB CommitOid: commitOid, RootOid: rootOid, Oid: oid, - Path: []byte(path.Join(rootPath, string(filename))), + Path: []byte(filepath.Join(rootPath, string(filename))), Type: objectType, Mode: int32(mode), }, nil diff --git a/internal/gitaly/service/namespace/namespace.go b/internal/gitaly/service/namespace/namespace.go index ec932732b..a06a63e04 100644 --- a/internal/gitaly/service/namespace/namespace.go +++ b/internal/gitaly/service/namespace/namespace.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "os" - "path" "path/filepath" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -119,5 +118,5 @@ func (s *server) RemoveNamespace(ctx context.Context, in *gitalypb.RemoveNamespa } func namespacePath(storage, ns string) string { - return path.Join(storage, ns) + return filepath.Join(storage, ns) } diff --git a/internal/gitaly/service/objectpool/create_test.go b/internal/gitaly/service/objectpool/create_test.go index 57279bf66..9962d5486 100644 --- a/internal/gitaly/service/objectpool/create_test.go +++ b/internal/gitaly/service/objectpool/create_test.go @@ -2,7 +2,6 @@ package objectpool import ( "os" - "path" "path/filepath" "strings" "testing" @@ -45,7 +44,7 @@ func TestCreate(t *testing.T) { require.True(t, pool.IsValid()) // No hooks - _, err = os.Stat(path.Join(pool.FullPath(), "hooks")) + _, err = os.Stat(filepath.Join(pool.FullPath(), "hooks")) assert.True(t, os.IsNotExist(err)) // No problems diff --git a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go index ccd9f6e09..064645f5e 100644 --- a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go +++ b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go @@ -3,7 +3,6 @@ package objectpool import ( "bytes" "encoding/json" - "path" "path/filepath" "strings" "testing" @@ -53,7 +52,7 @@ func TestFetchIntoObjectPool_Success(t *testing.T) { // No problems testhelper.MustRunCommand(t, nil, "git", "-C", pool.FullPath(), "fsck") - packFiles, err := filepath.Glob(path.Join(pool.FullPath(), "objects", "pack", "pack-*.pack")) + packFiles, err := filepath.Glob(filepath.Join(pool.FullPath(), "objects", "pack", "pack-*.pack")) require.NoError(t, err) require.Len(t, packFiles, 1, "ensure commits got packed") diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go index 8f774f454..cf1b4584c 100644 --- a/internal/gitaly/service/operations/tags_test.go +++ b/internal/gitaly/service/operations/tags_test.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "os" "os/exec" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -132,7 +132,7 @@ end`, command.GitPath()) dir, err := ioutil.TempDir("", "gitaly-temp-dir-*") require.NoError(t, err) - hookPath := path.Join(dir, "pre-receive") + hookPath := filepath.Join(dir, "pre-receive") require.NoError(t, ioutil.WriteFile(hookPath, []byte(hook), 0755)) @@ -160,7 +160,7 @@ end`, command.GitPath()) dir, err := ioutil.TempDir("", "gitaly-temp-dir-*") require.NoError(t, err) - hookPath := path.Join(dir, "pre-receive") + hookPath := filepath.Join(dir, "pre-receive") require.NoError(t, ioutil.WriteFile(hookPath, []byte(hook), 0755)) diff --git a/internal/gitaly/service/repository/apply_gitattributes.go b/internal/gitaly/service/repository/apply_gitattributes.go index e3ea85a01..9a89aef9d 100644 --- a/internal/gitaly/service/repository/apply_gitattributes.go +++ b/internal/gitaly/service/repository/apply_gitattributes.go @@ -6,7 +6,7 @@ import ( "io" "io/ioutil" "os" - "path" + "path/filepath" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/catfile" @@ -18,8 +18,8 @@ import ( const attributesFileMode os.FileMode = 0644 func applyGitattributes(c *catfile.Batch, repoPath string, revision []byte) error { - infoPath := path.Join(repoPath, "info") - attributesPath := path.Join(infoPath, "attributes") + infoPath := filepath.Join(repoPath, "info") + attributesPath := filepath.Join(infoPath, "attributes") _, err := c.Info(string(revision)) if err != nil { diff --git a/internal/gitaly/service/repository/apply_gitattributes_test.go b/internal/gitaly/service/repository/apply_gitattributes_test.go index b07fa4e4c..cbb3a8777 100644 --- a/internal/gitaly/service/repository/apply_gitattributes_test.go +++ b/internal/gitaly/service/repository/apply_gitattributes_test.go @@ -4,7 +4,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -23,9 +23,9 @@ func TestApplyGitattributesSuccess(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - infoPath := path.Join(testhelper.GitlabTestStoragePath(), + infoPath := filepath.Join(testhelper.GitlabTestStoragePath(), testRepo.GetRelativePath(), "info") - attributesPath := path.Join(infoPath, "attributes") + attributesPath := filepath.Join(infoPath, "attributes") tests := []struct { desc string diff --git a/internal/gitaly/service/repository/backup_custom_hooks.go b/internal/gitaly/service/repository/backup_custom_hooks.go index 39c287c89..b5dd32f93 100644 --- a/internal/gitaly/service/repository/backup_custom_hooks.go +++ b/internal/gitaly/service/repository/backup_custom_hooks.go @@ -3,7 +3,7 @@ package repository import ( "os" "os/exec" - "path" + "path/filepath" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -24,7 +24,7 @@ func (s *server) BackupCustomHooks(in *gitalypb.BackupCustomHooksRequest, stream return stream.Send(&gitalypb.BackupCustomHooksResponse{Data: p}) }) - if _, err := os.Lstat(path.Join(repoPath, customHooksDir)); os.IsNotExist(err) { + if _, err := os.Lstat(filepath.Join(repoPath, customHooksDir)); os.IsNotExist(err) { return nil } diff --git a/internal/gitaly/service/repository/backup_custom_hooks_test.go b/internal/gitaly/service/repository/backup_custom_hooks_test.go index 6494f7d81..8efcec4d5 100644 --- a/internal/gitaly/service/repository/backup_custom_hooks_test.go +++ b/internal/gitaly/service/repository/backup_custom_hooks_test.go @@ -7,7 +7,7 @@ import ( "io" "io/ioutil" "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -39,9 +39,9 @@ func TestSuccessfullBackupCustomHooksRequest(t *testing.T) { "custom_hooks/prepare-commit-msg.sample", "custom_hooks/pre-push.sample", } - require.NoError(t, os.Mkdir(path.Join(repoPath, "custom_hooks"), 0700), "Could not create custom_hooks dir") + require.NoError(t, os.Mkdir(filepath.Join(repoPath, "custom_hooks"), 0700), "Could not create custom_hooks dir") for _, fileName := range expectedTarResponse[1:] { - require.NoError(t, ioutil.WriteFile(path.Join(repoPath, fileName), []byte("Some hooks"), 0700), fmt.Sprintf("Could not create %s", fileName)) + require.NoError(t, ioutil.WriteFile(filepath.Join(repoPath, fileName), []byte("Some hooks"), 0700), fmt.Sprintf("Could not create %s", fileName)) } backupRequest := &gitalypb.BackupCustomHooksRequest{Repository: testRepo} @@ -83,7 +83,7 @@ func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) { require.NoError(t, err) linkTarget := "/var/empty" - require.NoError(t, os.Symlink(linkTarget, path.Join(repoPath, "custom_hooks")), "Could not create custom_hooks symlink") + require.NoError(t, os.Symlink(linkTarget, filepath.Join(repoPath, "custom_hooks")), "Could not create custom_hooks symlink") backupRequest := &gitalypb.BackupCustomHooksRequest{Repository: testRepo} backupStream, err := client.BackupCustomHooks(ctx, backupRequest) diff --git a/internal/gitaly/service/repository/calculate_checksum_test.go b/internal/gitaly/service/repository/calculate_checksum_test.go index 949c403b3..41835c720 100644 --- a/internal/gitaly/service/repository/calculate_checksum_test.go +++ b/internal/gitaly/service/repository/calculate_checksum_test.go @@ -3,7 +3,7 @@ package repository import ( "os" "os/exec" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -24,11 +24,11 @@ func TestSuccessfulCalculateChecksum(t *testing.T) { defer cleanupFn() // Force the refs database of testRepo into a known state - require.NoError(t, os.RemoveAll(path.Join(testRepoPath, "refs"))) + require.NoError(t, os.RemoveAll(filepath.Join(testRepoPath, "refs"))) for _, d := range []string{"refs/heads", "refs/tags", "refs/notes"} { - require.NoError(t, os.MkdirAll(path.Join(testRepoPath, d), 0755)) + require.NoError(t, os.MkdirAll(filepath.Join(testRepoPath, d), 0755)) } - require.NoError(t, exec.Command("cp", "testdata/checksum-test-packed-refs", path.Join(testRepoPath, "packed-refs")).Run()) + require.NoError(t, exec.Command("cp", "testdata/checksum-test-packed-refs", filepath.Join(testRepoPath, "packed-refs")).Run()) require.NoError(t, exec.Command(command.GitPath(), "-C", testRepoPath, "symbolic-ref", "HEAD", "refs/heads/feature").Run()) request := &gitalypb.CalculateChecksumRequest{Repository: testRepo} @@ -100,7 +100,7 @@ func TestBrokenRepositoryCalculateChecksum(t *testing.T) { defer cleanupFn() // Force an empty HEAD file - require.NoError(t, os.Truncate(path.Join(testRepoPath, "HEAD"), 0)) + require.NoError(t, os.Truncate(filepath.Join(testRepoPath, "HEAD"), 0)) request := &gitalypb.CalculateChecksumRequest{Repository: repo} testCtx, cancelCtx := testhelper.Context() @@ -156,11 +156,11 @@ func TestInvalidRefsCalculateChecksum(t *testing.T) { defer cleanupFn() // Force the refs database of testRepo into a known state - require.NoError(t, os.RemoveAll(path.Join(testRepoPath, "refs"))) + require.NoError(t, os.RemoveAll(filepath.Join(testRepoPath, "refs"))) for _, d := range []string{"refs/heads", "refs/tags", "refs/notes"} { - require.NoError(t, os.MkdirAll(path.Join(testRepoPath, d), 0755)) + require.NoError(t, os.MkdirAll(filepath.Join(testRepoPath, d), 0755)) } - require.NoError(t, exec.Command("cp", "testdata/checksum-test-invalid-refs", path.Join(testRepoPath, "packed-refs")).Run()) + require.NoError(t, exec.Command("cp", "testdata/checksum-test-invalid-refs", filepath.Join(testRepoPath, "packed-refs")).Run()) request := &gitalypb.CalculateChecksumRequest{Repository: testRepo} testCtx, cancelCtx := testhelper.Context() diff --git a/internal/gitaly/service/repository/create_from_bundle.go b/internal/gitaly/service/repository/create_from_bundle.go index 494e62906..67031d8ee 100644 --- a/internal/gitaly/service/repository/create_from_bundle.go +++ b/internal/gitaly/service/repository/create_from_bundle.go @@ -6,7 +6,7 @@ import ( "fmt" "io" "os" - "path" + "path/filepath" "strings" "gitlab.com/gitlab-org/gitaly/internal/git" @@ -57,7 +57,7 @@ func (s *server) CreateRepositoryFromBundle(stream gitalypb.RepositoryService_Cr return status.Error(codes.Internal, cleanError) } - bundlePath := path.Join(tmpDir, "repo.bundle") + bundlePath := filepath.Join(tmpDir, "repo.bundle") file, err := os.Create(bundlePath) if err != nil { cleanError := sanitizedError(tmpDir, "CreateRepositoryFromBundle: new bundle file failed: %v", err) diff --git a/internal/gitaly/service/repository/create_from_bundle_test.go b/internal/gitaly/service/repository/create_from_bundle_test.go index 20d544246..46262b34b 100644 --- a/internal/gitaly/service/repository/create_from_bundle_test.go +++ b/internal/gitaly/service/repository/create_from_bundle_test.go @@ -4,7 +4,7 @@ import ( "bytes" "io" "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -33,7 +33,7 @@ func TestSuccessfulCreateRepositoryFromBundleRequest(t *testing.T) { tmpdir, err := tempdir.New(ctx, testRepo) require.NoError(t, err) - bundlePath := path.Join(tmpdir, "original.bundle") + bundlePath := filepath.Join(tmpdir, "original.bundle") testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "update-ref", "refs/custom-refs/ref1", "HEAD") @@ -76,7 +76,7 @@ func TestSuccessfulCreateRepositoryFromBundleRequest(t *testing.T) { testhelper.MustRunCommand(t, nil, "git", "-C", importedRepoPath, "fsck") - info, err := os.Lstat(path.Join(importedRepoPath, "hooks")) + info, err := os.Lstat(filepath.Join(importedRepoPath, "hooks")) require.NoError(t, err) require.NotEqual(t, 0, info.Mode()&os.ModeSymlink) diff --git a/internal/gitaly/service/repository/create_from_url_test.go b/internal/gitaly/service/repository/create_from_url_test.go index b08737e38..41a114643 100644 --- a/internal/gitaly/service/repository/create_from_url_test.go +++ b/internal/gitaly/service/repository/create_from_url_test.go @@ -6,7 +6,6 @@ import ( "io/ioutil" "net/http" "os" - "path" "path/filepath" "testing" @@ -59,7 +58,7 @@ func TestSuccessfulCreateRepositoryFromURLRequest(t *testing.T) { remotes := testhelper.MustRunCommand(t, nil, "git", "-C", importedRepoPath, "remote") require.NotContains(t, string(remotes), "origin") - info, err := os.Lstat(path.Join(importedRepoPath, "hooks")) + info, err := os.Lstat(filepath.Join(importedRepoPath, "hooks")) require.NoError(t, err) require.NotEqual(t, 0, info.Mode()&os.ModeSymlink) } diff --git a/internal/gitaly/service/repository/create_test.go b/internal/gitaly/service/repository/create_test.go index 9fe052bb5..76e18470f 100644 --- a/internal/gitaly/service/repository/create_test.go +++ b/internal/gitaly/service/repository/create_test.go @@ -3,7 +3,7 @@ package repository import ( "fmt" "os" - "path" + "path/filepath" "strings" "testing" @@ -28,7 +28,7 @@ func TestCreateRepositorySuccess(t *testing.T) { storageDir, err := helper.GetStorageByName("default") require.NoError(t, err) relativePath := "create-repository-test.git" - repoDir := path.Join(storageDir, relativePath) + repoDir := filepath.Join(storageDir, relativePath) require.NoError(t, os.RemoveAll(repoDir)) repo := &gitalypb.Repository{StorageName: "default", RelativePath: relativePath} @@ -41,7 +41,7 @@ func TestCreateRepositorySuccess(t *testing.T) { require.NoError(t, err) require.Equal(t, "drwxr-x---", fi.Mode().String()) - for _, dir := range []string{repoDir, path.Join(repoDir, "refs")} { + for _, dir := range []string{repoDir, filepath.Join(repoDir, "refs")} { fi, err := os.Stat(dir) require.NoError(t, err) require.True(t, fi.IsDir(), "%q must be a directory", fi.Name()) @@ -60,7 +60,7 @@ func TestCreateRepositoryFailure(t *testing.T) { storagePath, err := helper.GetStorageByName("default") require.NoError(t, err) - fullPath := path.Join(storagePath, "foo.git") + fullPath := filepath.Join(storagePath, "foo.git") _, err = os.Create(fullPath) require.NoError(t, err) diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go index d9057d64a..7e0f0ad3c 100644 --- a/internal/gitaly/service/repository/fetch_remote_test.go +++ b/internal/gitaly/service/repository/fetch_remote_test.go @@ -7,7 +7,7 @@ import ( "net/http" "net/http/httptest" "os" - "path" + "path/filepath" "strings" "testing" @@ -26,7 +26,7 @@ func copyRepoWithNewRemote(t *testing.T, repo *gitalypb.Repository, remote strin cloneRepo := &gitalypb.Repository{StorageName: repo.GetStorageName(), RelativePath: "fetch-remote-clone.git"} - clonePath := path.Join(testhelper.GitlabTestStoragePath(), "fetch-remote-clone.git") + clonePath := filepath.Join(testhelper.GitlabTestStoragePath(), "fetch-remote-clone.git") t.Logf("clonePath: %q", clonePath) os.RemoveAll(clonePath) diff --git a/internal/gitaly/service/repository/fork_test.go b/internal/gitaly/service/repository/fork_test.go index c1fc3aea1..8f2b557cf 100644 --- a/internal/gitaly/service/repository/fork_test.go +++ b/internal/gitaly/service/repository/fork_test.go @@ -4,7 +4,7 @@ import ( "crypto/x509" "io/ioutil" "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -85,7 +85,7 @@ func TestSuccessfulCreateForkRequest(t *testing.T) { remotes := testhelper.MustRunCommand(t, nil, "git", "-C", forkedRepoPath, "remote") require.NotContains(t, string(remotes), "origin") - info, err := os.Lstat(path.Join(forkedRepoPath, "hooks")) + info, err := os.Lstat(filepath.Join(forkedRepoPath, "hooks")) require.NoError(t, err) require.NotEqual(t, 0, info.Mode()&os.ModeSymlink) }) diff --git a/internal/gitaly/service/repository/fsck_test.go b/internal/gitaly/service/repository/fsck_test.go index 05727d9ea..103d24404 100644 --- a/internal/gitaly/service/repository/fsck_test.go +++ b/internal/gitaly/service/repository/fsck_test.go @@ -2,7 +2,7 @@ package repository import ( "os" - "path" + "path/filepath" "strings" "testing" @@ -46,8 +46,8 @@ func TestFsckFailureSeverelyBrokenRepo(t *testing.T) { // This makes the repo severely broken so that `git` does not identify it as a // proper repo. - require.NoError(t, os.RemoveAll(path.Join(testRepoPath, "objects"))) - fd, err := os.Create(path.Join(testRepoPath, "objects")) + require.NoError(t, os.RemoveAll(filepath.Join(testRepoPath, "objects"))) + fd, err := os.Create(filepath.Join(testRepoPath, "objects")) require.NoError(t, err) require.NoError(t, fd.Close()) @@ -72,7 +72,7 @@ func TestFsckFailureSlightlyBrokenRepo(t *testing.T) { // This makes the repo slightly broken so that `git` still identify it as a // proper repo, but `fsck` complains about broken refs... - require.NoError(t, os.RemoveAll(path.Join(testRepoPath, "objects", "pack"))) + require.NoError(t, os.RemoveAll(filepath.Join(testRepoPath, "objects", "pack"))) c, err := client.Fsck(ctx, &gitalypb.FsckRequest{Repository: testRepo}) assert.NoError(t, err) diff --git a/internal/gitaly/service/repository/gc_test.go b/internal/gitaly/service/repository/gc_test.go index 8786522f3..2aa44778c 100644 --- a/internal/gitaly/service/repository/gc_test.go +++ b/internal/gitaly/service/repository/gc_test.go @@ -5,7 +5,6 @@ import ( "fmt" "io/ioutil" "os" - "path" "path/filepath" "testing" "time" @@ -88,7 +87,7 @@ func TestGarbageCollectSuccess(t *testing.T) { }, } - packPath := path.Join(testhelper.GitlabTestStoragePath(), testRepo.GetRelativePath(), "objects", "pack") + packPath := filepath.Join(testhelper.GitlabTestStoragePath(), testRepo.GetRelativePath(), "objects", "pack") for _, test := range tests { t.Run(test.desc, func(t *testing.T) { @@ -105,7 +104,7 @@ func TestGarbageCollectSuccess(t *testing.T) { // Entire `path`-folder gets updated so this is fine :D assertModTimeAfter(t, testTime, packPath) - bmPath, err := filepath.Glob(path.Join(packPath, "pack-*.bitmap")) + bmPath, err := filepath.Glob(filepath.Join(packPath, "pack-*.bitmap")) if err != nil { t.Fatalf("Error globbing bitmaps: %v", err) } diff --git a/internal/gitaly/service/repository/info_attributes.go b/internal/gitaly/service/repository/info_attributes.go index 4da30b99a..e1765cfba 100644 --- a/internal/gitaly/service/repository/info_attributes.go +++ b/internal/gitaly/service/repository/info_attributes.go @@ -3,7 +3,7 @@ package repository import ( "io" "os" - "path" + "path/filepath" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" @@ -17,7 +17,7 @@ func (s *server) GetInfoAttributes(in *gitalypb.GetInfoAttributesRequest, stream return err } - attrFile := path.Join(repoPath, "info", "attributes") + attrFile := filepath.Join(repoPath, "info", "attributes") f, err := os.Open(attrFile) if err != nil { if os.IsNotExist(err) { diff --git a/internal/gitaly/service/repository/info_attributes_test.go b/internal/gitaly/service/repository/info_attributes_test.go index 86096dc03..d599b2107 100644 --- a/internal/gitaly/service/repository/info_attributes_test.go +++ b/internal/gitaly/service/repository/info_attributes_test.go @@ -4,7 +4,7 @@ import ( "bytes" "io/ioutil" "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -23,12 +23,12 @@ func TestGetInfoAttributesExisting(t *testing.T) { testRepo, repoPath, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - infoPath := path.Join(repoPath, "info") + infoPath := filepath.Join(repoPath, "info") os.MkdirAll(infoPath, 0755) buffSize := streamio.WriteBufferSize + 1 data := bytes.Repeat([]byte("*.pbxproj binary\n"), buffSize) - attrsPath := path.Join(infoPath, "attributes") + attrsPath := filepath.Join(infoPath, "attributes") err := ioutil.WriteFile(attrsPath, data, 0644) require.NoError(t, err) diff --git a/internal/gitaly/service/repository/rebase_in_progress.go b/internal/gitaly/service/repository/rebase_in_progress.go index 9e149c85e..b72ead574 100644 --- a/internal/gitaly/service/repository/rebase_in_progress.go +++ b/internal/gitaly/service/repository/rebase_in_progress.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "os" - "path" + "path/filepath" "strings" "time" @@ -38,7 +38,7 @@ func (s *server) IsRebaseInProgress(ctx context.Context, req *gitalypb.IsRebaseI } func freshWorktree(ctx context.Context, repoPath, prefix, id string) (bool, error) { - worktreePath := path.Join(repoPath, worktreePrefix, fmt.Sprintf("%s-%s", prefix, id)) + worktreePath := filepath.Join(repoPath, worktreePrefix, fmt.Sprintf("%s-%s", prefix, id)) fs, err := os.Stat(worktreePath) if err != nil { diff --git a/internal/gitaly/service/repository/rebase_in_progress_test.go b/internal/gitaly/service/repository/rebase_in_progress_test.go index 9f99b678c..efc44b7ab 100644 --- a/internal/gitaly/service/repository/rebase_in_progress_test.go +++ b/internal/gitaly/service/repository/rebase_in_progress_test.go @@ -3,7 +3,7 @@ package repository import ( "fmt" "os" - "path" + "path/filepath" "testing" "time" @@ -23,9 +23,9 @@ func TestSuccessfulIsRebaseInProgressRequest(t *testing.T) { testRepo1, testRepo1Path, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", path.Join(testRepo1Path, worktreePrefix, fmt.Sprintf("%s-1", rebaseWorktreePrefix)), "master") + testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", filepath.Join(testRepo1Path, worktreePrefix, fmt.Sprintf("%s-1", rebaseWorktreePrefix)), "master") - brokenPath := path.Join(testRepo1Path, worktreePrefix, fmt.Sprintf("%s-2", rebaseWorktreePrefix)) + brokenPath := filepath.Join(testRepo1Path, worktreePrefix, fmt.Sprintf("%s-2", rebaseWorktreePrefix)) testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", brokenPath, "master") os.Chmod(brokenPath, 0) os.Chtimes(brokenPath, time.Now(), time.Now().Add(-16*time.Minute)) @@ -34,7 +34,7 @@ func TestSuccessfulIsRebaseInProgressRequest(t *testing.T) { os.RemoveAll(brokenPath) }() - oldPath := path.Join(testRepo1Path, worktreePrefix, fmt.Sprintf("%s-3", rebaseWorktreePrefix)) + oldPath := filepath.Join(testRepo1Path, worktreePrefix, fmt.Sprintf("%s-3", rebaseWorktreePrefix)) testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", oldPath, "master") os.Chtimes(oldPath, time.Now(), time.Now().Add(-16*time.Minute)) diff --git a/internal/gitaly/service/repository/repack_test.go b/internal/gitaly/service/repository/repack_test.go index 39d89d384..f84f99e97 100644 --- a/internal/gitaly/service/repository/repack_test.go +++ b/internal/gitaly/service/repository/repack_test.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "os/exec" - "path" "path/filepath" "strings" "testing" @@ -32,12 +31,12 @@ func TestRepackIncrementalSuccess(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - packPath := path.Join(testhelper.GitlabTestStoragePath(), testRepo.GetRelativePath(), "objects", "pack") + packPath := filepath.Join(testhelper.GitlabTestStoragePath(), testRepo.GetRelativePath(), "objects", "pack") // Reset mtime to a long while ago since some filesystems don't have sub-second // precision on `mtime`. // Stamp taken from https://golang.org/pkg/time/#pkg-constants - testhelper.MustRunCommand(t, nil, "touch", "-t", testTimeString, path.Join(packPath, "*")) + testhelper.MustRunCommand(t, nil, "touch", "-t", testTimeString, filepath.Join(packPath, "*")) testTime := time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC) ctx, cancel := testhelper.Context() defer cancel() @@ -108,7 +107,7 @@ func TestRepackLocal(t *testing.T) { _, err := client.RepackFull(ctx, &gitalypb.RepackFullRequest{Repository: testRepo}) require.NoError(t, err) - packFiles, err := filepath.Glob(path.Join(repoPath, ".git", "objects", "pack", "pack-*.pack")) + packFiles, err := filepath.Glob(filepath.Join(repoPath, ".git", "objects", "pack", "pack-*.pack")) require.NoError(t, err) require.Len(t, packFiles, 1) @@ -163,7 +162,7 @@ func TestRepackFullSuccess(t *testing.T) { {req: &gitalypb.RepackFullRequest{Repository: testRepo, CreateBitmap: false}, desc: "without bitmap"}, } - packPath := path.Join(testRepoPath, "objects", "pack") + packPath := filepath.Join(testRepoPath, "objects", "pack") for _, test := range tests { t.Run(test.desc, func(t *testing.T) { @@ -180,7 +179,7 @@ func TestRepackFullSuccess(t *testing.T) { // Entire `path`-folder gets updated so this is fine :D assertModTimeAfter(t, testTime, packPath) - bmPath, err := filepath.Glob(path.Join(packPath, "pack-*.bitmap")) + bmPath, err := filepath.Glob(filepath.Join(packPath, "pack-*.bitmap")) if err != nil { t.Fatalf("Error globbing bitmaps: %v", err) } diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go index 7f6922bde..8e79664e5 100644 --- a/internal/gitaly/service/repository/replicate_test.go +++ b/internal/gitaly/service/repository/replicate_test.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "net" "os" - "path" "path/filepath" "testing" @@ -63,7 +62,7 @@ func TestReplicateRepository(t *testing.T) { defer conn.Close() // write info attributes - attrFilePath := path.Join(testRepoPath, "info", "attributes") + attrFilePath := filepath.Join(testRepoPath, "info", "attributes") attrData := []byte("*.pbxproj binary\n") require.NoError(t, ioutil.WriteFile(attrFilePath, attrData, 0644)) @@ -86,7 +85,7 @@ func TestReplicateRepository(t *testing.T) { testhelper.MustRunCommand(t, nil, "git", "-C", targetRepoPath, "fsck") - replicatedAttrFilePath := path.Join(targetRepoPath, "info", "attributes") + replicatedAttrFilePath := filepath.Join(targetRepoPath, "info", "attributes") replicatedAttrData, err := ioutil.ReadFile(replicatedAttrFilePath) require.NoError(t, err) require.Equal(t, string(attrData), string(replicatedAttrData), "info/attributes files must match") diff --git a/internal/gitaly/service/repository/repository_test.go b/internal/gitaly/service/repository/repository_test.go index 9ea8c1270..7f914d886 100644 --- a/internal/gitaly/service/repository/repository_test.go +++ b/internal/gitaly/service/repository/repository_test.go @@ -3,7 +3,7 @@ package repository import ( "io/ioutil" "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -131,7 +131,7 @@ func TestSuccessfulHasLocalBranches(t *testing.T) { defer cleanupFn() emptyRepoName := "empty-repo.git" - emptyRepoPath := path.Join(testhelper.GitlabTestStoragePath(), emptyRepoName) + emptyRepoPath := filepath.Join(testhelper.GitlabTestStoragePath(), emptyRepoName) testhelper.MustRunCommand(t, nil, "git", "init", "--bare", emptyRepoPath) defer os.RemoveAll(emptyRepoPath) diff --git a/internal/gitaly/service/repository/restore_custom_hooks_test.go b/internal/gitaly/service/repository/restore_custom_hooks_test.go index f8e6ea806..d4eb5ca06 100644 --- a/internal/gitaly/service/repository/restore_custom_hooks_test.go +++ b/internal/gitaly/service/repository/restore_custom_hooks_test.go @@ -3,7 +3,7 @@ package repository import ( "io" "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -55,7 +55,7 @@ func TestSuccessfullRestoreCustomHooksRequest(t *testing.T) { _, err = stream.CloseAndRecv() require.NoError(t, err) - require.FileExists(t, path.Join(repoPath, "custom_hooks/pre-push.sample")) + require.FileExists(t, filepath.Join(repoPath, "custom_hooks", "pre-push.sample")) } func TestFailedRestoreCustomHooksDueToValidations(t *testing.T) { diff --git a/internal/gitaly/service/repository/search_files_test.go b/internal/gitaly/service/repository/search_files_test.go index 9f13b141d..aa625a272 100644 --- a/internal/gitaly/service/repository/search_files_test.go +++ b/internal/gitaly/service/repository/search_files_test.go @@ -5,7 +5,7 @@ import ( "fmt" "io" "io/ioutil" - "path" + "path/filepath" "strings" "testing" @@ -187,7 +187,7 @@ func TestSearchFilesByContentLargeFile(t *testing.T) { for _, largeFile := range largeFiles { t.Run(largeFile.filename, func(t *testing.T) { - require.NoError(t, ioutil.WriteFile(path.Join(testRepoPath, largeFile.filename), bytes.Repeat([]byte(largeFile.line), largeFile.repeated), 0644)) + require.NoError(t, ioutil.WriteFile(filepath.Join(testRepoPath, largeFile.filename), bytes.Repeat([]byte(largeFile.line), largeFile.repeated), 0644)) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "add", ".") testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "-c", fmt.Sprintf("user.name=%s", committerName), diff --git a/internal/gitaly/service/repository/snapshot_test.go b/internal/gitaly/service/repository/snapshot_test.go index 4802100fc..d6c35ac25 100644 --- a/internal/gitaly/service/repository/snapshot_test.go +++ b/internal/gitaly/service/repository/snapshot_test.go @@ -8,7 +8,6 @@ import ( "net/http/httptest" "os" "os/exec" - "path" "path/filepath" "strings" "testing" @@ -145,7 +144,7 @@ func TestGetSnapshotWithDedupe(t *testing.T) { // write alternates file to point to alt objects folder alternatesPath, err := git.InfoAlternatesPath(testRepo) require.NoError(t, err) - require.NoError(t, ioutil.WriteFile(alternatesPath, []byte(path.Join(repoPath, ".git", fmt.Sprintf("%s\n", alternateObjDir))), 0644)) + require.NoError(t, ioutil.WriteFile(alternatesPath, []byte(filepath.Join(repoPath, ".git", fmt.Sprintf("%s\n", alternateObjDir))), 0644)) // write another commit and ensure we can find it cmd = exec.Command(command.GitPath(), "-C", repoPath, @@ -175,7 +174,7 @@ func TestGetSnapshotWithDedupeSoftFailures(t *testing.T) { // write alternates file to point to alternates objects folder that doesn't exist alternateObjDir := "./alt-objects" - alternateObjPath := path.Join(repoPath, ".git", alternateObjDir) + alternateObjPath := filepath.Join(repoPath, ".git", alternateObjDir) alternatesPath, err := git.InfoAlternatesPath(testRepo) require.NoError(t, err) require.NoError(t, ioutil.WriteFile(alternatesPath, []byte(fmt.Sprintf("%s\n", alternateObjPath)), 0644)) diff --git a/internal/gitaly/service/repository/squash_in_progress_test.go b/internal/gitaly/service/repository/squash_in_progress_test.go index dda700870..72f0beda7 100644 --- a/internal/gitaly/service/repository/squash_in_progress_test.go +++ b/internal/gitaly/service/repository/squash_in_progress_test.go @@ -1,7 +1,7 @@ package repository import ( - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -20,7 +20,7 @@ func TestSuccessfulIsSquashInProgressRequest(t *testing.T) { testRepo1, testRepo1Path, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", path.Join(testRepo1Path, worktreePrefix, "squash-1"), "master") + testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", filepath.Join(testRepo1Path, worktreePrefix, "squash-1"), "master") testRepo2, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() diff --git a/internal/gitaly/service/repository/write_ref_test.go b/internal/gitaly/service/repository/write_ref_test.go index 9d3890a81..d84f8ec50 100644 --- a/internal/gitaly/service/repository/write_ref_test.go +++ b/internal/gitaly/service/repository/write_ref_test.go @@ -2,7 +2,7 @@ package repository import ( "bytes" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -61,7 +61,7 @@ func TestWriteRefSuccessful(t *testing.T) { require.NoError(t, err) if bytes.Equal(tc.req.Ref, []byte("HEAD")) { - content := testhelper.MustReadFile(t, path.Join(testRepoPath, "HEAD")) + content := testhelper.MustReadFile(t, filepath.Join(testRepoPath, "HEAD")) refRevision := bytes.Join([][]byte{[]byte("ref: "), tc.req.Revision, []byte("\n")}, nil) diff --git a/internal/gitaly/service/server/info.go b/internal/gitaly/service/server/info.go index 28e7fbdf5..0766aa374 100644 --- a/internal/gitaly/service/server/info.go +++ b/internal/gitaly/service/server/info.go @@ -4,7 +4,7 @@ import ( "context" "io/ioutil" "os" - "path" + "path/filepath" "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" @@ -54,7 +54,7 @@ func shardCheck(shardPath string) (readable bool, writeable bool) { } // the path uses a `+` to avoid naming collisions - testPath := path.Join(shardPath, "+testWrite") + testPath := filepath.Join(shardPath, "+testWrite") content := []byte("testWrite") if err := ioutil.WriteFile(testPath, content, 0644); err == nil { diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go index 75ad7a3af..abb27c363 100644 --- a/internal/gitaly/service/smarthttp/receive_pack_test.go +++ b/internal/gitaly/service/smarthttp/receive_pack_test.go @@ -8,7 +8,6 @@ import ( "io/ioutil" "net" "os" - "path" "path/filepath" "strings" "testing" @@ -152,7 +151,7 @@ func TestFailedReceivePackRequestDueToHooksFailure(t *testing.T) { require.NoError(t, os.MkdirAll(hooks.Path(), 0755)) hookContent := []byte("#!/bin/sh\nexit 1") - ioutil.WriteFile(path.Join(hooks.Path(), "pre-receive"), hookContent, 0755) + ioutil.WriteFile(filepath.Join(hooks.Path(), "pre-receive"), hookContent, 0755) serverSocketPath, stop := runSmartHTTPServer(t) defer stop() @@ -249,7 +248,7 @@ func createCommit(t *testing.T, repoPath string, fileContents []byte) (oldHead s oldHead = text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", "master")) changedFile := "README.md" - require.NoError(t, ioutil.WriteFile(path.Join(repoPath, changedFile), fileContents, 0644)) + require.NoError(t, ioutil.WriteFile(filepath.Join(repoPath, changedFile), fileContents, 0644)) testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "add", changedFile) testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, diff --git a/internal/gitaly/service/smarthttp/upload_pack_test.go b/internal/gitaly/service/smarthttp/upload_pack_test.go index 2077904a6..235b25882 100644 --- a/internal/gitaly/service/smarthttp/upload_pack_test.go +++ b/internal/gitaly/service/smarthttp/upload_pack_test.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "os" - "path" "path/filepath" "testing" "time" @@ -47,8 +46,8 @@ func TestSuccessfulUploadPackRequest(t *testing.T) { storagePath := testhelper.GitlabTestStoragePath() remoteRepoRelativePath := "gitlab-test-remote" localRepoRelativePath := "gitlab-test-local" - remoteRepoPath := path.Join(storagePath, remoteRepoRelativePath) - localRepoPath := path.Join(storagePath, localRepoRelativePath) + remoteRepoPath := filepath.Join(storagePath, remoteRepoRelativePath) + localRepoPath := filepath.Join(storagePath, localRepoRelativePath) // Make a non-bare clone of the test repo to act as a remote one testhelper.MustRunCommand(t, nil, "git", "clone", testRepoPath, remoteRepoPath) // Make a bare clone of the test repo to act as a local one and to leave the original repo intact for other tests @@ -82,7 +81,7 @@ func TestSuccessfulUploadPackRequest(t *testing.T) { req := &gitalypb.PostUploadPackRequest{ Repository: &gitalypb.Repository{ StorageName: "default", - RelativePath: path.Join(remoteRepoRelativePath, ".git"), + RelativePath: filepath.Join(remoteRepoRelativePath, ".git"), }, } responseBuffer, err := makePostUploadPackRequest(ctx, t, serverSocketPath, req, requestBuffer) @@ -116,7 +115,7 @@ func TestUploadPackRequestWithGitConfigOptions(t *testing.T) { storagePath := testhelper.GitlabTestStoragePath() ourRepoRelativePath := "gitlab-test-remote" - ourRepoPath := path.Join(storagePath, ourRepoRelativePath) + ourRepoPath := filepath.Join(storagePath, ourRepoRelativePath) // Make a clone of the test repo to modify testhelper.MustRunCommand(t, nil, "git", "clone", "--bare", testRepoPath, ourRepoPath) @@ -342,8 +341,8 @@ func TestUploadPackRequestForPartialCloneSuccess(t *testing.T) { storagePath := testhelper.GitlabTestStoragePath() remoteRepoRelativePath := "gitlab-test-remote" localRepoRelativePath := "gitlab-test-local" - remoteRepoPath := path.Join(storagePath, remoteRepoRelativePath) - localRepoPath := path.Join(storagePath, localRepoRelativePath) + remoteRepoPath := filepath.Join(storagePath, remoteRepoRelativePath) + localRepoPath := filepath.Join(storagePath, localRepoRelativePath) // Make a non-bare clone of the test repo to act as a remote one testhelper.MustRunCommand(t, nil, "git", "clone", testRepoPath, remoteRepoPath) // Make a bare clone of the test repo to act as a local one and to leave the original repo intact for other tests @@ -378,7 +377,7 @@ func TestUploadPackRequestForPartialCloneSuccess(t *testing.T) { req := &gitalypb.PostUploadPackRequest{ Repository: &gitalypb.Repository{ StorageName: "default", - RelativePath: path.Join(remoteRepoRelativePath, ".git"), + RelativePath: filepath.Join(remoteRepoRelativePath, ".git"), }, } diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go index 515c3a047..3dc204975 100644 --- a/internal/gitaly/service/ssh/receive_pack_test.go +++ b/internal/gitaly/service/ssh/receive_pack_test.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "os" "os/exec" - "path" "path/filepath" "strings" "testing" @@ -155,7 +154,7 @@ func TestReceivePackPushHookFailure(t *testing.T) { require.NoError(t, os.MkdirAll(hooks.Path(), 0755)) hookContent := []byte("#!/bin/sh\nexit 1") - ioutil.WriteFile(path.Join(hooks.Path(), "pre-receive"), hookContent, 0755) + ioutil.WriteFile(filepath.Join(hooks.Path(), "pre-receive"), hookContent, 0755) _, _, err = testCloneAndPush(t, serverSocketPath, pushParams{storageName: testRepo.GetStorageName(), glID: "1"}) require.Error(t, err) @@ -277,9 +276,9 @@ type SSHCloneDetails struct { func setupSSHClone(t *testing.T) (SSHCloneDetails, func()) { storagePath := testhelper.GitlabTestStoragePath() tempRepo := "gitlab-test-ssh-receive-pack.git" - testRepoPath := path.Join(storagePath, testRepo.GetRelativePath()) - remoteRepoPath := path.Join(storagePath, tempRepo) - localRepoPath := path.Join(storagePath, "gitlab-test-ssh-receive-pack-local") + testRepoPath := filepath.Join(storagePath, testRepo.GetRelativePath()) + remoteRepoPath := filepath.Join(storagePath, tempRepo) + localRepoPath := filepath.Join(storagePath, "gitlab-test-ssh-receive-pack-local") // Make a bare clone of the test repo to act as a remote one and to leave the original repo intact for other tests if err := os.RemoveAll(remoteRepoPath); err != nil && !os.IsNotExist(err) { t.Fatal(err) diff --git a/internal/gitaly/service/ssh/testhelper_test.go b/internal/gitaly/service/ssh/testhelper_test.go index 5729f98be..6884fa3b9 100644 --- a/internal/gitaly/service/ssh/testhelper_test.go +++ b/internal/gitaly/service/ssh/testhelper_test.go @@ -2,7 +2,6 @@ package ssh import ( "os" - "path" "path/filepath" "testing" @@ -48,7 +47,7 @@ func testMain(m *testing.M) int { testhelper.ConfigureGitalyHooksBinary() testhelper.ConfigureGitalySSH() - gitalySSHPath = path.Join(config.Config.BinDir, "gitaly-ssh") + gitalySSHPath = filepath.Join(config.Config.BinDir, "gitaly-ssh") return m.Run() } diff --git a/internal/gitaly/service/ssh/upload_pack_test.go b/internal/gitaly/service/ssh/upload_pack_test.go index b59ce5b2d..62fb7e0f9 100644 --- a/internal/gitaly/service/ssh/upload_pack_test.go +++ b/internal/gitaly/service/ssh/upload_pack_test.go @@ -5,7 +5,7 @@ import ( "io" "os" "os/exec" - "path" + "path/filepath" "strings" "testing" "time" @@ -75,7 +75,7 @@ func (cmd cloneCommand) test(t *testing.T, localRepoPath string) (string, string require.NoError(t, err) storagePath := testhelper.GitlabTestStoragePath() - testRepoPath := path.Join(storagePath, testRepo.GetRelativePath()) + testRepoPath := filepath.Join(storagePath, testRepo.GetRelativePath()) remoteHead := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", "master")) localHead := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", localRepoPath, "rev-parse", "master")) @@ -198,7 +198,7 @@ func TestUploadPackCloneSuccess(t *testing.T) { ) defer stop() - localRepoPath := path.Join(testRepoRoot, "gitlab-test-upload-pack-local") + localRepoPath := filepath.Join(testRepoRoot, "gitlab-test-upload-pack-local") tests := []struct { cmd *exec.Cmd @@ -269,7 +269,7 @@ func TestUploadPackCloneWithPartialCloneFilter(t *testing.T) { // Run the clone with filtering enabled in both runs. The only // difference is that in the first run, we have the // UploadPackFilter flag disabled. - localPath := path.Join(testRepoRoot, fmt.Sprintf("gitlab-test-upload-pack-local-%s", tc.desc)) + localPath := filepath.Join(testRepoRoot, fmt.Sprintf("gitlab-test-upload-pack-local-%s", tc.desc)) cmd := cloneCommand{ repository: testRepo, command: exec.Command(command.GitPath(), append(tc.cloneArgs, localPath)...), @@ -286,7 +286,7 @@ func TestUploadPackCloneWithPartialCloneFilter(t *testing.T) { } func TestUploadPackCloneSuccessWithGitProtocol(t *testing.T) { - localRepoPath := path.Join(testRepoRoot, "gitlab-test-upload-pack-local") + localRepoPath := filepath.Join(testRepoRoot, "gitlab-test-upload-pack-local") tests := []struct { cmd *exec.Cmd @@ -332,7 +332,7 @@ func TestUploadPackCloneHideTags(t *testing.T) { serverSocketPath, stop := runSSHServer(t) defer stop() - localRepoPath := path.Join(testRepoRoot, "gitlab-test-upload-pack-local-hide-tags") + localRepoPath := filepath.Join(testRepoRoot, "gitlab-test-upload-pack-local-hide-tags") cmd := cloneCommand{ repository: testRepo, @@ -354,7 +354,7 @@ func TestUploadPackCloneFailure(t *testing.T) { serverSocketPath, stop := runSSHServer(t) defer stop() - localRepoPath := path.Join(testRepoRoot, "gitlab-test-upload-pack-local-failure") + localRepoPath := filepath.Join(testRepoRoot, "gitlab-test-upload-pack-local-failure") cmd := cloneCommand{ repository: &gitalypb.Repository{ diff --git a/internal/gitaly/service/wiki/find_file_test.go b/internal/gitaly/service/wiki/find_file_test.go index eea64cc52..73e7de7a9 100644 --- a/internal/gitaly/service/wiki/find_file_test.go +++ b/internal/gitaly/service/wiki/find_file_test.go @@ -5,7 +5,7 @@ import ( "io" "io/ioutil" "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -27,7 +27,7 @@ func TestSuccessfulWikiFindFileRequest(t *testing.T) { committerName := "Scrooge McDuck" committerEmail := "scrooge@mcduck.com" storagePath := testhelper.GitlabTestStoragePath() - sandboxWikiPath := path.Join(storagePath, "find-file-sandbox") + sandboxWikiPath := filepath.Join(storagePath, "find-file-sandbox") testhelper.MustRunCommand(t, nil, "git", "clone", wikiRepoPath, sandboxWikiPath) defer os.RemoveAll(sandboxWikiPath) @@ -40,10 +40,10 @@ func TestSuccessfulWikiFindFileRequest(t *testing.T) { content, err := ioutil.ReadFile("testdata/clouds.png") require.NoError(t, err) - err = ioutil.WriteFile(path.Join(sandboxWikiPath, "cloúds.png"), content, 0644) + err = ioutil.WriteFile(filepath.Join(sandboxWikiPath, "cloúds.png"), content, 0644) require.NoError(t, err) - err = ioutil.WriteFile(path.Join(sandboxWikiPath, "no_content.png"), nil, 0644) + err = ioutil.WriteFile(filepath.Join(sandboxWikiPath, "no_content.png"), nil, 0644) require.NoError(t, err) // Sandbox wiki is empty, so we create a commit to be used later diff --git a/internal/gitaly/service/wiki/testhelper_test.go b/internal/gitaly/service/wiki/testhelper_test.go index 45f8b38c8..0a1ed1e79 100644 --- a/internal/gitaly/service/wiki/testhelper_test.go +++ b/internal/gitaly/service/wiki/testhelper_test.go @@ -4,7 +4,7 @@ import ( "bytes" "io/ioutil" "os" - "path" + "path/filepath" "strings" "testing" @@ -156,7 +156,7 @@ func updateWikiPage(t *testing.T, client gitalypb.WikiServiceClient, wikiRepo *g func setupWikiRepo(t *testing.T) (*gitalypb.Repository, string, func()) { relPath := strings.Join([]string{t.Name(), "wiki-test.git"}, "-") storagePath := testhelper.GitlabTestStoragePath() - wikiRepoPath := path.Join(storagePath, relPath) + wikiRepoPath := filepath.Join(storagePath, relPath) testhelper.MustRunCommand(nil, nil, "git", "init", "--bare", wikiRepoPath) diff --git a/internal/helper/repo.go b/internal/helper/repo.go index 76bc2b33a..7c9d51351 100644 --- a/internal/helper/repo.go +++ b/internal/helper/repo.go @@ -2,7 +2,7 @@ package helper import ( "os" - "path" + "path/filepath" "gitlab.com/gitlab-org/gitaly/internal/git/repository" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" @@ -61,7 +61,7 @@ func GetPath(repo repository.GitRepo) (string, error) { return "", status.Errorf(codes.InvalidArgument, "GetRepoPath: %s", err) } - return path.Join(storagePath, relativePath), nil + return filepath.Join(storagePath, relativePath), nil } // GetStorageByName will return the path for the storage, which is fetched by @@ -94,7 +94,7 @@ func GetObjectDirectoryPath(repo repository.GitRepo) (string, error) { return "", status.Errorf(codes.InvalidArgument, "GetObjectDirectoryPath: %s", err) } - fullPath := path.Join(repoPath, objectDirectoryPath) + fullPath := filepath.Join(repoPath, objectDirectoryPath) if _, err := os.Stat(fullPath); os.IsNotExist(err) { return "", status.Errorf(codes.NotFound, "GetObjectDirectoryPath: does not exist '%s'", fullPath) } diff --git a/internal/helper/repo_test.go b/internal/helper/repo_test.go index 86c86e9b8..9a9f3578a 100644 --- a/internal/helper/repo_test.go +++ b/internal/helper/repo_test.go @@ -2,7 +2,7 @@ package helper import ( "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -195,8 +195,8 @@ func TestGetRepoPath(t *testing.T) { } func assertInvalidRepoWithoutFile(t *testing.T, repo *gitalypb.Repository, repoPath, file string) { - oldRoute := path.Join(repoPath, file) - renamedRoute := path.Join(repoPath, file+"moved") + oldRoute := filepath.Join(repoPath, file) + renamedRoute := filepath.Join(repoPath, file+"moved") os.Rename(oldRoute, renamedRoute) defer func() { os.Rename(renamedRoute, oldRoute) @@ -210,7 +210,7 @@ func assertInvalidRepoWithoutFile(t *testing.T, repo *gitalypb.Repository, repoP func TestGetRepoPathWithCorruptedRepo(t *testing.T) { testRepo := testhelper.TestRepository() testRepoStoragePath := testhelper.GitlabTestStoragePath() - testRepoPath := path.Join(testRepoStoragePath, testRepo.RelativePath) + testRepoPath := filepath.Join(testRepoStoragePath, testRepo.RelativePath) for _, file := range []string{"objects", "refs", "HEAD"} { assertInvalidRepoWithoutFile(t, testRepo, testRepoPath, file) @@ -233,7 +233,7 @@ func TestGetObjectDirectoryPath(t *testing.T) { { desc: "storages configured", repo: &gitalypb.Repository{StorageName: "default", RelativePath: testhelper.TestRelativePath, GitObjectDirectory: "objects/"}, - path: path.Join(repoPath, "objects/"), + path: filepath.Join(repoPath, "objects/"), }, { desc: "no GitObjectDirectoryPath", diff --git a/internal/linguist/linguist.go b/internal/linguist/linguist.go index dcd02f473..29916e934 100644 --- a/internal/linguist/linguist.go +++ b/internal/linguist/linguist.go @@ -9,7 +9,7 @@ import ( "io/ioutil" "os" "os/exec" - "path" + "path/filepath" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" @@ -97,7 +97,7 @@ func startGitLinguist(ctx context.Context, repoPath string, commitID string, lin // Git's directory to PATH. But as our internal command interface will // overwrite PATH even if we pass it in here, we need to work around it // and instead execute the command with `env PATH=$GITDIR:$PATH`. - gitDir := path.Dir(command.GitPath()) + gitDir := filepath.Dir(command.GitPath()) if path, ok := os.LookupEnv("PATH"); ok && gitDir != "." { args = append([]string{ "env", fmt.Sprintf("PATH=%s:%s", gitDir, path), @@ -152,7 +152,7 @@ func openLanguagesJSON(cfg config.Cfg) (io.ReadCloser, error) { return nil, err } - return os.Open(path.Join(linguistPathSymlink.Name(), "lib/linguist/languages.json")) + return os.Open(filepath.Join(linguistPathSymlink.Name(), "lib", "linguist", "languages.json")) } func exportEnvironment() []string { diff --git a/internal/storage/locator.go b/internal/storage/locator.go index d20400c1e..43fce7f5b 100644 --- a/internal/storage/locator.go +++ b/internal/storage/locator.go @@ -3,7 +3,6 @@ package storage import ( "errors" "os" - "path" "path/filepath" "strings" @@ -53,7 +52,7 @@ func IsGitDirectory(dir string) bool { } for _, element := range []string{"objects", "refs", "HEAD"} { - if _, err := os.Stat(path.Join(dir, element)); err != nil { + if _, err := os.Stat(filepath.Join(dir, element)); err != nil { return false } } @@ -66,7 +65,7 @@ func IsGitDirectory(dir string) bool { // git gc runs for a long time while keeping open the packed-refs file. // Running stat() on the file causes the kernel to revalidate the cached // directory entry. We don't actually care if this file exists. - os.Stat(path.Join(dir, "packed-refs")) + os.Stat(filepath.Join(dir, "packed-refs")) return true } diff --git a/internal/supervisor/supervisor_test.go b/internal/supervisor/supervisor_test.go index 40ebaf27e..2af3b655f 100644 --- a/internal/supervisor/supervisor_test.go +++ b/internal/supervisor/supervisor_test.go @@ -7,7 +7,6 @@ import ( "net" "os" "os/exec" - "path" "path/filepath" "strconv" "syscall" @@ -43,7 +42,7 @@ func testMain(m *testing.M) int { log.Fatal(err) } - testExe = path.Join(testDir, "pid-server") + testExe = filepath.Join(testDir, "pid-server") buildCmd := exec.Command("go", "build", "-o", testExe, scriptPath) buildCmd.Dir = filepath.Dir(scriptPath) buildCmd.Stderr = os.Stderr @@ -52,7 +51,7 @@ func testMain(m *testing.M) int { log.Fatal(err) } - socketPath = path.Join(testDir, "socket") + socketPath = filepath.Join(testDir, "socket") return m.Run() } @@ -99,7 +98,7 @@ func TestSpawnFailure(t *testing.T) { config.CrashWaitTime = 2 * time.Second - notFoundExe := path.Join(testDir, "not-found") + notFoundExe := filepath.Join(testDir, "not-found") require.NoError(t, os.RemoveAll(notFoundExe)) defer os.Remove(notFoundExe) diff --git a/internal/tempdir/tempdir_test.go b/internal/tempdir/tempdir_test.go index 6c5af4990..37595be87 100644 --- a/internal/tempdir/tempdir_test.go +++ b/internal/tempdir/tempdir_test.go @@ -3,7 +3,7 @@ package tempdir import ( "io/ioutil" "os" - "path" + "path/filepath" "testing" "time" @@ -30,7 +30,7 @@ func TestNewAsRepositorySuccess(t *testing.T) { require.NoError(t, err) require.Equal(t, tempDir, calculatedPath) - err = ioutil.WriteFile(path.Join(tempDir, "test"), []byte("hello"), 0644) + err = ioutil.WriteFile(filepath.Join(tempDir, "test"), []byte("hello"), 0644) require.NoError(t, err, "write file in tempdir") cancel() // This should trigger async removal of the temporary directory @@ -54,7 +54,7 @@ func TestNewAsRepositoryFailStorageUnknown(t *testing.T) { require.Error(t, err) } -var cleanRoot = path.Join("testdata/clean", tmpRootPrefix) +var cleanRoot = filepath.Join("testdata", "clean", tmpRootPrefix) func TestCleanerSafety(t *testing.T) { defer func() { @@ -121,11 +121,11 @@ func TestCleanTempDir(t *testing.T) { } func chmod(p string, mode os.FileMode) error { - return os.Chmod(path.Join(cleanRoot, p), mode) + return os.Chmod(filepath.Join(cleanRoot, p), mode) } func chtimes(p string, t time.Time) error { - return os.Chtimes(path.Join(cleanRoot, p), t, t) + return os.Chtimes(filepath.Join(cleanRoot, p), t, t) } func assertEntries(t *testing.T, entries ...string) { @@ -140,20 +140,20 @@ func assertEntries(t *testing.T, entries ...string) { } func makeFile(t *testing.T, filePath string, mtime time.Time) { - fullPath := path.Join(cleanRoot, filePath) + fullPath := filepath.Join(cleanRoot, filePath) require.NoError(t, ioutil.WriteFile(fullPath, nil, 0644)) require.NoError(t, os.Chtimes(fullPath, mtime, mtime)) } func makeDir(t *testing.T, dirPath string, mtime time.Time) { - fullPath := path.Join(cleanRoot, dirPath) + fullPath := filepath.Join(cleanRoot, dirPath) require.NoError(t, os.MkdirAll(fullPath, 0700)) require.NoError(t, os.Chtimes(fullPath, mtime, mtime)) } func TestCleanNoTmpExists(t *testing.T) { // This directory is valid because it ends in the special prefix - dir := path.Join("testdata", "does-not-exist", tmpRootPrefix) + dir := filepath.Join("testdata", "does-not-exist", tmpRootPrefix) require.NoError(t, clean(dir)) } diff --git a/internal/testhelper/commit.go b/internal/testhelper/commit.go index 3769f0b66..12cdbf0ee 100644 --- a/internal/testhelper/commit.go +++ b/internal/testhelper/commit.go @@ -5,7 +5,7 @@ import ( "fmt" "os" "os/exec" - "path" + "path/filepath" "strings" "testing" @@ -64,12 +64,12 @@ func CreateCommit(t testing.TB, repoPath, branchName string, opts *CreateCommitO // objects will live in an alternate objects directory. It returns the current // head after the command is run and the alternate objects directory path func CreateCommitInAlternateObjectDirectory(t testing.TB, repoPath, altObjectsDir string, cmd *exec.Cmd) (currentHead []byte) { - gitPath := path.Join(repoPath, ".git") + gitPath := filepath.Join(repoPath, ".git") - altObjectsPath := path.Join(gitPath, altObjectsDir) + altObjectsPath := filepath.Join(gitPath, altObjectsDir) gitObjectEnv := []string{ fmt.Sprintf("GIT_OBJECT_DIRECTORY=%s", altObjectsPath), - fmt.Sprintf("GIT_ALTERNATE_OBJECT_DIRECTORIES=%s", path.Join(gitPath, "objects")), + fmt.Sprintf("GIT_ALTERNATE_OBJECT_DIRECTORIES=%s", filepath.Join(gitPath, "objects")), } require.NoError(t, os.MkdirAll(altObjectsPath, 0755)) diff --git a/internal/testhelper/git_protocol.go b/internal/testhelper/git_protocol.go index 7ba4ddb6f..0e0a3690a 100644 --- a/internal/testhelper/git_protocol.go +++ b/internal/testhelper/git_protocol.go @@ -4,7 +4,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -26,7 +26,7 @@ exec "%s" "$@" dir, err := ioutil.TempDir("", "gitaly-test-*") require.NoError(t, err) - path := path.Join(dir, "git") + path := filepath.Join(dir, "git") cleanup, err := WriteExecutable(path, []byte(script)) require.NoError(t, err) diff --git a/internal/testhelper/hook_env.go b/internal/testhelper/hook_env.go index e46177843..6960c924e 100644 --- a/internal/testhelper/hook_env.go +++ b/internal/testhelper/hook_env.go @@ -4,7 +4,6 @@ import ( "io/ioutil" "log" "os" - "path" "path/filepath" "testing" @@ -45,7 +44,7 @@ func ConfigureGitalyHooksBinary() { goBuildArgs := []string{ "build", "-o", - path.Join(config.Config.BinDir, "gitaly-hooks"), + filepath.Join(config.Config.BinDir, "gitaly-hooks"), "gitlab.com/gitlab-org/gitaly/cmd/gitaly-hooks", } MustRunCommand(nil, nil, "go", goBuildArgs...) diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index fd0b23387..5c8be0bcb 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -18,7 +18,6 @@ import ( "net" "os" "os/exec" - "path" "path/filepath" "runtime" "sort" @@ -126,7 +125,7 @@ func GitlabTestStoragePath() string { if !ok { log.Fatal("Could not get caller info") } - return path.Join(path.Dir(currentFile), "testdata/data") + return filepath.Join(filepath.Dir(currentFile), "testdata", "data") } // GitalyServersMetadata returns a metadata pair for gitaly-servers to be used in @@ -531,7 +530,7 @@ func initRepo(t testing.TB, bare bool) (*gitalypb.Repository, string, func()) { repo := CreateRepo(t, storagePath, relativePath) if !bare { - repo.RelativePath = path.Join(repo.RelativePath, ".git") + repo.RelativePath = filepath.Join(repo.RelativePath, ".git") } return repo, repoPath, func() { require.NoError(t, os.RemoveAll(repoPath)) } @@ -574,7 +573,7 @@ func cloneTestRepo(t testing.TB, storageRoot, relativePath string, bare bool) (r args = append(args, "--bare") } else { // For non-bare repos the relative path is the .git folder inside the path - repo.RelativePath = path.Join(relativePath, ".git") + repo.RelativePath = filepath.Join(relativePath, ".git") } MustRunCommand(t, nil, "git", append(args, testRepositoryPath(t), repoPath)...) @@ -602,7 +601,7 @@ func ConfigureGitalySSH() { goBuildArgs := []string{ "build", "-o", - path.Join(config.Config.BinDir, "gitaly-ssh"), + filepath.Join(config.Config.BinDir, "gitaly-ssh"), "gitlab.com/gitlab-org/gitaly/cmd/gitaly-ssh", } MustRunCommand(nil, nil, "go", goBuildArgs...) @@ -617,7 +616,7 @@ func ConfigureGitalyGit2Go() { goBuildArgs := []string{ "build", "-tags", "static,system_libgit2", - "-o", path.Join(config.Config.BinDir, "gitaly-git2go"), + "-o", filepath.Join(config.Config.BinDir, "gitaly-git2go"), "gitlab.com/gitlab-org/gitaly/cmd/gitaly-git2go", } MustRunCommand(nil, nil, "go", goBuildArgs...) @@ -678,7 +677,7 @@ func TempDir(t testing.TB) (string, func()) { log.Fatal("Could not get caller info") } - rootTmpDir := path.Join(path.Dir(currentFile), "testdata/tmp") + rootTmpDir := filepath.Join(filepath.Dir(currentFile), "testdata", "tmp") tmpDir, err := ioutil.TempDir(rootTmpDir, "") require.NoError(t, err) return tmpDir, func() { require.NoError(t, os.RemoveAll(tmpDir)) } diff --git a/internal/x509/pool_darwin.go b/internal/x509/pool_darwin.go index b898c686b..d7614da77 100644 --- a/internal/x509/pool_darwin.go +++ b/internal/x509/pool_darwin.go @@ -5,7 +5,7 @@ import ( "errors" "io/ioutil" "os" - "path" + "path/filepath" ) // SystemCertPool circumvents the fact that Go on macOS does not support @@ -34,7 +34,7 @@ func SystemCertPool() (*x509.CertPool, error) { continue } - pem, err := ioutil.ReadFile(path.Join(d, entry.Name())) + pem, err := ioutil.ReadFile(filepath.Join(d, entry.Name())) if err != nil { return nil, err } |