Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-03-11 11:01:38 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-03-11 14:29:31 +0300
commitb95b97ab27707a70a16ecad8cd3fdaa01b329bf4 (patch)
tree2497604f91514c9f1d5598221a44c85211d9eca3
parent5379be27793df28194af2b6d107efd59c3cb7974 (diff)
locator: Return proper error code if repo paths do not exist
When retrieving the path of a repository via `GetPath()`, we call stat(3P) on the calculated path in order to determine whether the repository exists or not. In case the stat(3P) call errors, we always return an internal code. This isn't ideal though: while the error may be because of whatever reason, the most likely reason is that the target path simply doesn't exist. Returning an internal code is not ideal in that case. Fix the issue by returning a `NotFound` code in case the error returned by stat(3P) is ENOENT.
-rw-r--r--internal/gitaly/config/locator.go3
-rw-r--r--internal/gitaly/service/repository/repository_test.go2
2 files changed, 4 insertions, 1 deletions
diff --git a/internal/gitaly/config/locator.go b/internal/gitaly/config/locator.go
index a06ad4e8a..a5fdea3c5 100644
--- a/internal/gitaly/config/locator.go
+++ b/internal/gitaly/config/locator.go
@@ -52,6 +52,9 @@ func (l *configLocator) GetPath(repo repository.GitRepo) (string, error) {
}
if _, err := os.Stat(storagePath); err != nil {
+ if os.IsNotExist(err) {
+ return "", status.Errorf(codes.NotFound, "GetPath: does not exist: %v", err)
+ }
return "", status.Errorf(codes.Internal, "GetPath: storage path: %v", err)
}
diff --git a/internal/gitaly/service/repository/repository_test.go b/internal/gitaly/service/repository/repository_test.go
index dc24e2d5e..22db3659a 100644
--- a/internal/gitaly/service/repository/repository_test.go
+++ b/internal/gitaly/service/repository/repository_test.go
@@ -101,7 +101,7 @@ func TestRepositoryExists(t *testing.T) {
RelativePath: "foobar.git",
},
},
- errorCode: codes.Internal,
+ errorCode: codes.NotFound,
},
}