Skip to content

Commit 88aa395

Browse files
committed
command: skip a directory if gitbase has no permission to read it
Fixes #718 When a child of one of the paths given to the gitbase server is not readable because of permissions, the repo finding process just stopped and no repository was added to the pool. This skips a directory if there are no permissions to read it, so the process can continue adding repositories to the pool as usual. Signed-off-by: Miguel Molina <[email protected]>
1 parent e01f718 commit 88aa395

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

_testdata/not-permission/.gitkeep

Whitespace-only changes.

cmd/gitbase/command/server.go

+3
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ func (c *Server) addMatch(match string) error {
309309
initDepth := strings.Count(root, string(os.PathSeparator))
310310
return filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
311311
if err != nil {
312+
if os.IsPermission(err) {
313+
return filepath.SkipDir
314+
}
312315
return err
313316
}
314317

cmd/gitbase/command/server_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package command
22

33
import (
4+
"os"
45
"testing"
56

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

14+
notPermissionDir := "../../../_testdata/not-permission/"
15+
fi, err := os.Stat(notPermissionDir)
16+
require.NoError(err)
17+
18+
require.NoError(os.Chmod(notPermissionDir, 0))
19+
defer func() {
20+
require.NoError(os.Chmod(notPermissionDir, fi.Mode()))
21+
}()
22+
1323
expected := []struct {
1424
path string
1525
err func(error, ...interface{})
1626
}{
1727
{"../../../_testdata/repositories/", require.NoError},
1828
{"../../../_testdata/repositories-link/", require.NoError},
29+
{notPermissionDir, require.NoError},
1930
{"../../../_testdata/repositories-not-exist/", require.Error},
2031
}
2132
c := &Server{pool: gitbase.NewRepositoryPool(0)}

0 commit comments

Comments
 (0)