mirror of
https://github.com/go-gitea/gitea
synced 2024-11-16 07:04:25 +00:00
Backport #27266 by @merlleu Hello there, Cargo Index over HTTP is now prefered over git for package updates: we should not force users who do not need the GIT repo to have the repo created/updated on each publish (it can still be created in the packages settings). The current behavior when publishing is to check if the repo exist and create it on the fly if not, then update it's content. Cargo HTTP Index does not rely on the repo itself so this will be useless for everyone not using the git protocol for cargo registry. This PR only disable the creation on the fly of the repo when publishing a crate. This is linked to #26844 (error 500 when trying to publish a crate if user is missing write access to the repo) because it's now optional. Co-authored-by: merlleu <r.langdorph@gmail.com> Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
This commit is contained in:
parent
95db95ef91
commit
77bd3acb65
@ -250,7 +250,7 @@ func UploadPackage(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cargo_service.AddOrUpdatePackageIndex(ctx, ctx.Doer, ctx.Package.Owner, pv.PackageID); err != nil {
|
if err := cargo_service.UpdatePackageIndexIfExists(ctx, ctx.Doer, ctx.Package.Owner, pv.PackageID); err != nil {
|
||||||
if err := packages_service.DeletePackageVersionAndReferences(ctx, pv); err != nil {
|
if err := packages_service.DeletePackageVersionAndReferences(ctx, pv); err != nil {
|
||||||
log.Error("Rollback creation of package version: %v", err)
|
log.Error("Rollback creation of package version: %v", err)
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ func yankPackage(ctx *context.Context, yank bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cargo_service.AddOrUpdatePackageIndex(ctx, ctx.Doer, ctx.Package.Owner, pv.PackageID); err != nil {
|
if err := cargo_service.UpdatePackageIndexIfExists(ctx, ctx.Doer, ctx.Package.Owner, pv.PackageID); err != nil {
|
||||||
apiError(ctx, http.StatusInternalServerError, err)
|
apiError(ctx, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -106,10 +106,16 @@ func RebuildIndex(ctx context.Context, doer, owner *user_model.User) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddOrUpdatePackageIndex(ctx context.Context, doer, owner *user_model.User, packageID int64) error {
|
func UpdatePackageIndexIfExists(ctx context.Context, doer, owner *user_model.User, packageID int64) error {
|
||||||
repo, err := getOrCreateIndexRepository(ctx, doer, owner)
|
// We do not want to force the creation of the repo here
|
||||||
|
// cargo http index does not rely on the repo itself,
|
||||||
|
// so if the repo does not exist, we just do nothing.
|
||||||
|
repo, err := repo_model.GetRepositoryByOwnerAndName(ctx, owner.Name, IndexRepositoryName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("GetRepositoryByOwnerAndName: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := packages_model.GetPackageByID(ctx, packageID)
|
p, err := packages_model.GetPackageByID(ctx, packageID)
|
||||||
|
@ -110,8 +110,8 @@ func ExecuteCleanupRules(outerCtx context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetUserByID failed: %w", err)
|
return fmt.Errorf("GetUserByID failed: %w", err)
|
||||||
}
|
}
|
||||||
if err := cargo_service.AddOrUpdatePackageIndex(ctx, owner, owner, p.ID); err != nil {
|
if err := cargo_service.UpdatePackageIndexIfExists(ctx, owner, owner, p.ID); err != nil {
|
||||||
return fmt.Errorf("CleanupRule [%d]: cargo.AddOrUpdatePackageIndex failed: %w", pcr.ID, err)
|
return fmt.Errorf("CleanupRule [%d]: cargo.UpdatePackageIndexIfExists failed: %w", pcr.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user