Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix repository adoption on Windows (#21646) #21650

Merged
merged 3 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions services/repository/adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"os"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions services/repository/adopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
Expand All @@ -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))
Expand Down