diff options
Diffstat (limited to 'models/packages/package_file.go')
-rw-r--r-- | models/packages/package_file.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/models/packages/package_file.go b/models/packages/package_file.go index 1c2c9ac072..1bb6b57a34 100644 --- a/models/packages/package_file.go +++ b/models/packages/package_file.go @@ -46,18 +46,18 @@ type PackageFile struct { func TryInsertFile(ctx context.Context, pf *PackageFile) (*PackageFile, error) { e := db.GetEngine(ctx) - key := &PackageFile{ - VersionID: pf.VersionID, - LowerName: pf.LowerName, - CompositeKey: pf.CompositeKey, - } + existing := &PackageFile{} - has, err := e.Get(key) + has, err := e.Where(builder.Eq{ + "version_id": pf.VersionID, + "lower_name": pf.LowerName, + "composite_key": pf.CompositeKey, + }).Get(existing) if err != nil { return nil, err } if has { - return pf, ErrDuplicatePackageFile + return existing, ErrDuplicatePackageFile } if _, err = e.Insert(pf); err != nil { return nil, err @@ -93,13 +93,13 @@ func GetFileForVersionByName(ctx context.Context, versionID int64, name, key str return nil, ErrPackageFileNotExist } - pf := &PackageFile{ - VersionID: versionID, - LowerName: strings.ToLower(name), - CompositeKey: key, - } + pf := &PackageFile{} - has, err := db.GetEngine(ctx).Get(pf) + has, err := db.GetEngine(ctx).Where(builder.Eq{ + "version_id": versionID, + "lower_name": strings.ToLower(name), + "composite_key": key, + }).Get(pf) if err != nil { return nil, err } |