Skip to content

Commit 3a0d000

Browse files
authored
Fix repository adoption on Windows (#21646) (#21650)
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 fd4e744 commit 3a0d000

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

services/repository/adopt.go

+6-5
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

@@ -218,21 +219,21 @@ func DeleteUnadoptedRepository(doer, u *user_model.User, repoName string) error
218219
return util.RemoveAll(repoPath)
219220
}
220221

221-
type unadoptedRrepositories struct {
222+
type unadoptedRepositories struct {
222223
repositories []string
223224
index int
224225
start int
225226
end int
226227
}
227228

228-
func (unadopted *unadoptedRrepositories) add(repository string) {
229+
func (unadopted *unadoptedRepositories) add(repository string) {
229230
if unadopted.index >= unadopted.start && unadopted.index < unadopted.end {
230231
unadopted.repositories = append(unadopted.repositories, repository)
231232
}
232233
unadopted.index++
233234
}
234235

235-
func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unadopted *unadoptedRrepositories) error {
236+
func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unadopted *unadoptedRepositories) error {
236237
if len(repoNamesToCheck) == 0 {
237238
return nil
238239
}
@@ -264,7 +265,7 @@ func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unad
264265
}
265266
for _, repoName := range repoNamesToCheck {
266267
if !repoNames.Contains(repoName) {
267-
unadopted.add(filepath.Join(userName, repoName))
268+
unadopted.add(path.Join(userName, repoName)) // These are not used as filepaths - but as reponames - therefore use path.Join not filepath.Join
268269
}
269270
}
270271
return nil
@@ -292,7 +293,7 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
292293
var repoNamesToCheck []string
293294

294295
start := (opts.Page - 1) * opts.PageSize
295-
unadopted := &unadoptedRrepositories{
296+
unadopted := &unadoptedRepositories{
296297
repositories: make([]string, 0, opts.PageSize),
297298
start: start,
298299
end: start + opts.PageSize,

services/repository/adopt_test.go

+4-4
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)