diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-04-15 05:15:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-14 22:15:28 +0100 |
commit | dc5a1d617d4a7bf1da77a473cd9b251a35ba5d74 (patch) | |
tree | f32d42b036e348bc052a40f498ed413876c5ee5e /modules/repository/fork.go | |
parent | cf8f66e5dcebc07fd1975806e94b69ad557a13ed (diff) | |
download | gitea-dc5a1d617d4a7bf1da77a473cd9b251a35ba5d74.tar.gz gitea-dc5a1d617d4a7bf1da77a473cd9b251a35ba5d74.zip |
Fix potential copy lfs records failure when fork a repository (#15441)
Diffstat (limited to 'modules/repository/fork.go')
-rw-r--r-- | modules/repository/fork.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/modules/repository/fork.go b/modules/repository/fork.go index cdd08e3d3c..f8cb74bcb4 100644 --- a/modules/repository/fork.go +++ b/modules/repository/fork.go @@ -64,6 +64,12 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name, return err } + // copy lfs files failure should not be ignored + if err := models.CopyLFS(ctx, repo, oldRepo); err != nil { + rollbackRemoveFn() + return err + } + repoPath := models.RepoPath(owner.Name, repo.Name) if stdout, err := git.NewCommand( "clone", "--bare", oldRepoPath, repoPath). @@ -92,6 +98,7 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name, return nil, err } + // even if below operations failed, it could be ignored. And they will be retried ctx := models.DefaultDBContext() if err = repo.UpdateSize(ctx); err != nil { log.Error("Failed to update size for repository: %v", err) @@ -100,11 +107,5 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name, log.Error("Copy language stat from oldRepo failed") } - if err := models.CopyLFS(ctx, repo, oldRepo); err != nil { - if errDelete := models.DeleteRepository(doer, owner.ID, repo.ID); errDelete != nil { - log.Error("Rollback deleteRepository: %v", errDelete) - } - return nil, err - } return repo, nil } |