mirror of
https://github.com/go-gitea/gitea
synced 2024-09-01 03:56:10 +02:00
Add transaction for CreateRepoByExample
This commit is contained in:
parent
2c02c2eb47
commit
d66b9059a2
@ -66,7 +66,10 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
|
||||
}
|
||||
}
|
||||
|
||||
if err := repo_module.CreateRepositoryByExample(ctx, doer, u, repo, true, false); err != nil {
|
||||
// create the repository database operations first
|
||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
return repo_module.CreateRepositoryByExample(ctx, doer, u, repo, true, false)
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -241,9 +241,11 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
|
||||
ObjectFormatName: opts.ObjectFormatName,
|
||||
}
|
||||
|
||||
needsUpdateStatus := opts.Status == 0
|
||||
needsUpdateStatus := opts.Status != repo_model.RepositoryReady
|
||||
|
||||
if err := repo_module.CreateRepositoryByExample(ctx, doer, u, repo, false, false); err != nil {
|
||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
return repo_module.CreateRepositoryByExample(ctx, doer, u, repo, false, false)
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
system_model "code.gitea.io/gitea/models/system"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
@ -338,12 +340,26 @@ func generateRepository(ctx context.Context, doer, owner *user_model.User, templ
|
||||
Status: repo_model.RepositoryBeingMigrated,
|
||||
}
|
||||
|
||||
if err = repo_module.CreateRepositoryByExample(ctx, doer, owner, generateRepo, false, false); err != nil {
|
||||
if err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
return repo_module.CreateRepositoryByExample(ctx, doer, owner, generateRepo, false, false)
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repoPath := generateRepo.RepoPath()
|
||||
isExist, err := util.IsExist(repoPath)
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if errDelete := DeleteRepositoryDirectly(ctx, doer, generateRepo.ID); errDelete != nil {
|
||||
log.Error("Rollback deleteRepository: %v", errDelete)
|
||||
// add system notice
|
||||
if err := system_model.CreateRepositoryNotice("DeleteRepositoryDirectly failed when generate repository: %v", errDelete); err != nil {
|
||||
log.Error("CreateRepositoryNotice: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user