Skip to content

Commit bff75ca

Browse files
authored
Merge pull request #597 from BakeRolls/server-follow-symlink
Server follow symlinks when passed as an argument
2 parents 42bbeca + 0815b90 commit bff75ca

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

_testdata/repositories-link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./repositories
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
repositories-link

cmd/gitbase/command/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ func (c *Server) addMatch(match string) error {
295295
if err != nil {
296296
return err
297297
}
298+
root, err = filepath.EvalSymlinks(root)
299+
if err != nil {
300+
return err
301+
}
298302

299303
initDepth := strings.Count(root, string(os.PathSeparator))
300304
return filepath.Walk(root, func(path string, info os.FileInfo, err error) error {

cmd/gitbase/command/server_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package command
2+
3+
import (
4+
"testing"
5+
6+
"github.com/src-d/gitbase"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestAddMatch(t *testing.T) {
11+
require := require.New(t)
12+
13+
expected := []struct {
14+
path string
15+
err func(error, ...interface{})
16+
}{
17+
{"../../../_testdata/repositories/", require.NoError},
18+
{"../../../_testdata/repositories-link/", require.NoError},
19+
{"../../../_testdata/repositories-not-exist/", require.Error},
20+
}
21+
c := &Server{pool: gitbase.NewRepositoryPool(0)}
22+
for _, e := range expected {
23+
e.err(c.addMatch(e.path))
24+
}
25+
}

0 commit comments

Comments
 (0)