aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-10-31 23:16:48 +0000
committerGitHub <noreply@github.com>2022-10-31 23:16:48 +0000
commitf211d235c7a42c03f97697878550dc49b65e93da (patch)
treec97b2ee92da0fe7a265963931b586c28ac4cebdb /services
parent563945c50cec4d3bb839a783b8d4604271fdbf09 (diff)
downloadgitea-f211d235c7a42c03f97697878550dc49b65e93da.tar.gz
gitea-f211d235c7a42c03f97697878550dc49b65e93da.zip
Fix repository adoption on Windows (#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 <art27@cantab.net>
Diffstat (limited to 'services')
-rw-r--r--services/repository/adopt.go11
-rw-r--r--services/repository/adopt_test.go8
2 files changed, 10 insertions, 9 deletions
diff --git a/services/repository/adopt.go b/services/repository/adopt.go
index 3b986c66c6..a9a0639548 100644
--- a/services/repository/adopt.go
+++ b/services/repository/adopt.go
@@ -8,6 +8,7 @@ import (
"context"
"fmt"
"os"
+ "path"
"path/filepath"
"strings"
@@ -218,21 +219,21 @@ func DeleteUnadoptedRepository(doer, u *user_model.User, repoName string) error
return util.RemoveAll(repoPath)
}
-type unadoptedRrepositories struct {
+type unadoptedRepositories struct {
repositories []string
index int
start int
end int
}
-func (unadopted *unadoptedRrepositories) add(repository string) {
+func (unadopted *unadoptedRepositories) add(repository string) {
if unadopted.index >= unadopted.start && unadopted.index < unadopted.end {
unadopted.repositories = append(unadopted.repositories, repository)
}
unadopted.index++
}
-func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unadopted *unadoptedRrepositories) error {
+func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unadopted *unadoptedRepositories) error {
if len(repoNamesToCheck) == 0 {
return nil
}
@@ -264,7 +265,7 @@ func checkUnadoptedRepositories(userName string, repoNamesToCheck []string, unad
}
for _, repoName := range repoNamesToCheck {
if !repoNames.Contains(repoName) {
- unadopted.add(filepath.Join(userName, repoName))
+ unadopted.add(path.Join(userName, repoName)) // These are not used as filepaths - but as reponames - therefore use path.Join not filepath.Join
}
}
return nil
@@ -292,7 +293,7 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
var repoNamesToCheck []string
start := (opts.Page - 1) * opts.PageSize
- unadopted := &unadoptedRrepositories{
+ unadopted := &unadoptedRepositories{
repositories: make([]string, 0, opts.PageSize),
start: start,
end: start + opts.PageSize,
diff --git a/services/repository/adopt_test.go b/services/repository/adopt_test.go
index 685bfe9bc4..b450005f34 100644
--- a/services/repository/adopt_test.go
+++ b/services/repository/adopt_test.go
@@ -19,7 +19,7 @@ import (
func TestCheckUnadoptedRepositories_Add(t *testing.T) {
start := 10
end := 20
- unadopted := &unadoptedRrepositories{
+ unadopted := &unadoptedRepositories{
start: start,
end: end,
index: 0,
@@ -39,7 +39,7 @@ func TestCheckUnadoptedRepositories(t *testing.T) {
//
// Non existent user
//
- unadopted := &unadoptedRrepositories{start: 0, end: 100}
+ unadopted := &unadoptedRepositories{start: 0, end: 100}
err := checkUnadoptedRepositories("notauser", []string{"repo"}, unadopted)
assert.NoError(t, err)
assert.Equal(t, 0, len(unadopted.repositories))
@@ -50,14 +50,14 @@ func TestCheckUnadoptedRepositories(t *testing.T) {
userName := "user2"
repoName := "repo2"
unadoptedRepoName := "unadopted"
- unadopted = &unadoptedRrepositories{start: 0, end: 100}
+ unadopted = &unadoptedRepositories{start: 0, end: 100}
err = checkUnadoptedRepositories(userName, []string{repoName, unadoptedRepoName}, unadopted)
assert.NoError(t, err)
assert.Equal(t, []string{path.Join(userName, unadoptedRepoName)}, unadopted.repositories)
//
// Existing (adopted) repository is not returned
//
- unadopted = &unadoptedRrepositories{start: 0, end: 100}
+ unadopted = &unadoptedRepositories{start: 0, end: 100}
err = checkUnadoptedRepositories(userName, []string{repoName}, unadopted)
assert.NoError(t, err)
assert.Equal(t, 0, len(unadopted.repositories))