aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-04-29 02:14:26 +0800
committerGitHub <noreply@github.com>2023-04-28 14:14:26 -0400
commita6450494c3a9c05667ae8a2ebdfdea55b8206e9b (patch)
treee4c6eba554eb4866337f82f2f96521b4b9370f84 /models/repo
parent572af214a7256fde76d0fa69fc5791b1758455ef (diff)
downloadgitea-a6450494c3a9c05667ae8a2ebdfdea55b8206e9b.tar.gz
gitea-a6450494c3a9c05667ae8a2ebdfdea55b8206e9b.zip
Fix unclear `IsRepositoryExist` logic (#24374)
There was only one `IsRepositoryExist` function, it did: `has && isDir` However it's not right, and it would cause 500 error when creating a new repository if the dir exists. Then, it was changed to `has || isDir`, it is still incorrect, it affects the "adopt repo" logic. To make the logic clear: * IsRepositoryModelOrDirExist * IsRepositoryModelExist
Diffstat (limited to 'models/repo')
-rw-r--r--models/repo/repo.go16
-rw-r--r--models/repo/update.go4
2 files changed, 12 insertions, 8 deletions
diff --git a/models/repo/repo.go b/models/repo/repo.go
index f9de6d493d..2e8c28cbb3 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -726,12 +726,9 @@ func GetRepositoriesMapByIDs(ids []int64) (map[int64]*Repository, error) {
return repos, db.GetEngine(db.DefaultContext).In("id", ids).Find(&repos)
}
-// IsRepositoryExist returns true if the repository with given name under user has already existed.
-func IsRepositoryExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
- has, err := db.GetEngine(ctx).Get(&Repository{
- OwnerID: u.ID,
- LowerName: strings.ToLower(repoName),
- })
+// IsRepositoryModelOrDirExist returns true if the repository with given name under user has already existed.
+func IsRepositoryModelOrDirExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
+ has, err := IsRepositoryModelExist(ctx, u, repoName)
if err != nil {
return false, err
}
@@ -739,6 +736,13 @@ func IsRepositoryExist(ctx context.Context, u *user_model.User, repoName string)
return has || isDir, err
}
+func IsRepositoryModelExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
+ return db.GetEngine(ctx).Get(&Repository{
+ OwnerID: u.ID,
+ LowerName: strings.ToLower(repoName),
+ })
+}
+
// GetTemplateRepo populates repo.TemplateRepo for a generated repository and
// returns an error on failure (NOTE: no error is returned for
// non-generated repositories, and TemplateRepo will be left untouched)
diff --git a/models/repo/update.go b/models/repo/update.go
index f4cb67bb8f..4894e0a1b9 100644
--- a/models/repo/update.go
+++ b/models/repo/update.go
@@ -116,7 +116,7 @@ func CheckCreateRepository(doer, u *user_model.User, name string, overwriteOrAdo
return err
}
- has, err := IsRepositoryExist(db.DefaultContext, u, name)
+ has, err := IsRepositoryModelOrDirExist(db.DefaultContext, u, name)
if err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {
@@ -147,7 +147,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
return err
}
- has, err := IsRepositoryExist(db.DefaultContext, repo.Owner, newRepoName)
+ has, err := IsRepositoryModelOrDirExist(db.DefaultContext, repo.Owner, newRepoName)
if err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {