Skip to content

Commit

Permalink
Merge pull request #738 from erizocosmico/fix/skip-no-access-dirs
Browse files Browse the repository at this point in the history
command: skip a directory if gitbase has no permission to read it
  • Loading branch information
ajnavarro committed Mar 20, 2019
2 parents e01f718 + 88aa395 commit 8c6f7d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
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

0 comments on commit 8c6f7d6

Please sign in to comment.