Skip to content

Commit d6d62c0

Browse files
authored
Fix repository adoption on Windows (#21646) (#21651)
Backport #21646 A bug was introduced in #17865 where filepath.Join is used to join putative unadopted repository owner and names together. This is incorrect as these names are then used as repository names - which shoud have the '/' separator. This means that adoption will not work on Windows servers. Fix #21632 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 7a2daae commit d6d62c0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

services/repository/adopt.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"os"
11+
"path"
1112
"path/filepath"
1213
"strings"
1314

@@ -220,21 +221,21 @@ func DeleteUnadoptedRepository(doer, u *user_model.User, repoName string) error
220221
return util.RemoveAll(repoPath)
221222
}
222223

223-
type unadoptedRrepositories struct {
224+
type unadoptedRepositories struct {
224225
repositories []string
225226
index int
226227
start int
227228
end int
228229
}
229230

230-
func (unadopted *unadoptedRrepositories) add(repository string) {
231+
func (unadopted *unadoptedRepositories) add(repository string) {
231232
if unadopted.index >= unadopted.start && unadopted.index < unadopted.end {
232233
unadopted.repositories = append(unadopted.repositories, repository)
233234
}
234235
unadopted.index++
235236
}
236237

237-
func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unadopted *unadoptedRrepositories) error {
238+
func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unadopted *unadoptedRepositories) error {
238239
if len(repoNamesToCheck) == 0 {
239240
return nil
240241
}
@@ -266,7 +267,7 @@ func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unad
266267
}
267268
for _, repoName := range repoNamesToCheck {
268269
if _, ok := repoNames[repoName]; !ok {
269-
unadopted.add(filepath.Join(userName, repoName))
270+
unadopted.add(path.Join(userName, repoName)) // These are not used as filepaths - but as reponames - therefore use path.Join not filepath.Join
270271
}
271272
}
272273
return nil
@@ -294,7 +295,7 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
294295
var repoNamesToCheck []string
295296

296297
start := (opts.Page - 1) * opts.PageSize
297-
unadopted := &unadoptedRrepositories{
298+
unadopted := &unadoptedRepositories{
298299
repositories: make([]string, 0, opts.PageSize),
299300
start: start,
300301
end: start + opts.PageSize,

services/repository/adopt_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
func TestCheckUnadoptedRepositories_Add(t *testing.T) {
2020
start := 10
2121
end := 20
22-
unadopted := &unadoptedRrepositories{
22+
unadopted := &unadoptedRepositories{
2323
start: start,
2424
end: end,
2525
index: 0,
@@ -39,7 +39,7 @@ func TestCheckUnadoptedRepositories(t *testing.T) {
3939
//
4040
// Non existent user
4141
//
42-
unadopted := &unadoptedRrepositories{start: 0, end: 100}
42+
unadopted := &unadoptedRepositories{start: 0, end: 100}
4343
err := checkUnadoptedRepositories("notauser", []string{"repo"}, unadopted)
4444
assert.NoError(t, err)
4545
assert.Equal(t, 0, len(unadopted.repositories))
@@ -50,14 +50,14 @@ func TestCheckUnadoptedRepositories(t *testing.T) {
5050
userName := "user2"
5151
repoName := "repo2"
5252
unadoptedRepoName := "unadopted"
53-
unadopted = &unadoptedRrepositories{start: 0, end: 100}
53+
unadopted = &unadoptedRepositories{start: 0, end: 100}
5454
err = checkUnadoptedRepositories(userName, []string{repoName, unadoptedRepoName}, unadopted)
5555
assert.NoError(t, err)
5656
assert.Equal(t, []string{path.Join(userName, unadoptedRepoName)}, unadopted.repositories)
5757
//
5858
// Existing (adopted) repository is not returned
5959
//
60-
unadopted = &unadoptedRrepositories{start: 0, end: 100}
60+
unadopted = &unadoptedRepositories{start: 0, end: 100}
6161
err = checkUnadoptedRepositories(userName, []string{repoName}, unadopted)
6262
assert.NoError(t, err)
6363
assert.Equal(t, 0, len(unadopted.repositories))

0 commit comments

Comments
 (0)