0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-23 07:43:18 -05:00

Fix potential copy lfs records failure when fork a repository (#15441)

This commit is contained in:
Lunny Xiao 2021-04-15 05:15:28 +08:00 committed by GitHub
parent cf8f66e5dc
commit dc5a1d617d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,6 +64,12 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
return err 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) repoPath := models.RepoPath(owner.Name, repo.Name)
if stdout, err := git.NewCommand( if stdout, err := git.NewCommand(
"clone", "--bare", oldRepoPath, repoPath). "clone", "--bare", oldRepoPath, repoPath).
@ -92,6 +98,7 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
return nil, err return nil, err
} }
// even if below operations failed, it could be ignored. And they will be retried
ctx := models.DefaultDBContext() ctx := models.DefaultDBContext()
if err = repo.UpdateSize(ctx); err != nil { if err = repo.UpdateSize(ctx); err != nil {
log.Error("Failed to update size for repository: %v", err) 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") 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 return repo, nil
} }