Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command: skip a directory if gitbase has no permission to read it #738

Merged
merged 1 commit into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
3 changes: 3 additions & 0 deletions cmd/gitbase/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ func (c *Server) addMatch(match string) error {
initDepth := strings.Count(root, string(os.PathSeparator))
return filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
if os.IsPermission(err) {
return filepath.SkipDir
}
return err
}

Expand Down
11 changes: 11 additions & 0 deletions cmd/gitbase/command/server_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"os"
"testing"

"github.com/src-d/gitbase"
Expand All @@ -10,12 +11,22 @@ import (
func TestAddMatch(t *testing.T) {
require := require.New(t)

notPermissionDir := "../../../_testdata/not-permission/"
fi, err := os.Stat(notPermissionDir)
require.NoError(err)

require.NoError(os.Chmod(notPermissionDir, 0))
defer func() {
require.NoError(os.Chmod(notPermissionDir, fi.Mode()))
}()

expected := []struct {
path string
err func(error, ...interface{})
}{
{"../../../_testdata/repositories/", require.NoError},
{"../../../_testdata/repositories-link/", require.NoError},
{notPermissionDir, require.NoError},
{"../../../_testdata/repositories-not-exist/", require.Error},
}
c := &Server{pool: gitbase.NewRepositoryPool(0)}
Expand Down