aboutsummaryrefslogtreecommitdiffstats
path: root/services/packages/packages.go
diff options
context:
space:
mode:
Diffstat (limited to 'services/packages/packages.go')
-rw-r--r--services/packages/packages.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/services/packages/packages.go b/services/packages/packages.go
index 55351afce2..bd1d460fd3 100644
--- a/services/packages/packages.go
+++ b/services/packages/packages.go
@@ -132,12 +132,11 @@ func createPackageAndVersion(ctx context.Context, pvci *PackageCreationInfo, all
}
var err error
if p, err = packages_model.TryInsertPackage(ctx, p); err != nil {
- if err == packages_model.ErrDuplicatePackage {
- packageCreated = false
- } else {
+ if !errors.Is(err, packages_model.ErrDuplicatePackage) {
log.Error("Error inserting package: %v", err)
return nil, false, err
}
+ packageCreated = false
}
if packageCreated {
@@ -163,11 +162,10 @@ func createPackageAndVersion(ctx context.Context, pvci *PackageCreationInfo, all
MetadataJSON: string(metadataJSON),
}
if pv, err = packages_model.GetOrInsertVersion(ctx, pv); err != nil {
- if err == packages_model.ErrDuplicatePackageVersion {
+ if errors.Is(err, packages_model.ErrDuplicatePackageVersion) && allowDuplicate {
versionCreated = false
- }
- if err != packages_model.ErrDuplicatePackageVersion || !allowDuplicate {
- log.Error("Error inserting package: %v", err)
+ } else {
+ log.Error("Error inserting package: %v", err) // other error, or disallowing duplicates
return nil, false, err
}
}
@@ -433,7 +431,7 @@ func GetOrCreateInternalPackageVersion(ctx context.Context, ownerID int64, packa
}
var err error
if p, err = packages_model.TryInsertPackage(ctx, p); err != nil {
- if err != packages_model.ErrDuplicatePackage {
+ if !errors.Is(err, packages_model.ErrDuplicatePackage) {
log.Error("Error inserting package: %v", err)
return err
}