@@ -42,7 +42,7 @@ func GetRepositoryKey(ctx *context.Context) {
4242}
4343
4444func UploadPackageFile (ctx * context.Context ) {
45- repository := strings .TrimSpace (ctx .Params ("repository" ))
45+ repository := strings .TrimSpace (ctx .PathParam ("repository" ))
4646 if repository == "" {
4747 apiError (ctx , http .StatusBadRequest , "invalid repository" )
4848 return
@@ -96,6 +96,32 @@ func UploadPackageFile(ctx *context.Context) {
9696 return
9797 }
9898
99+ release , err := arch_service .AquireRegistryLock (ctx , ctx .Package .Owner .ID )
100+ if err != nil {
101+ apiError (ctx , http .StatusInternalServerError , err )
102+ return
103+ }
104+ defer release ()
105+
106+ // Search for duplicates with different file compression
107+ has , err := packages_model .HasFiles (ctx , & packages_model.PackageFileSearchOptions {
108+ OwnerID : ctx .Package .Owner .ID ,
109+ PackageType : packages_model .TypeArch ,
110+ Query : fmt .Sprintf ("%s-%s-%s.pkg.tar.%%" , pck .Name , pck .Version , pck .FileMetadata .Architecture ),
111+ Properties : map [string ]string {
112+ arch_module .PropertyRepository : repository ,
113+ arch_module .PropertyArchitecture : pck .FileMetadata .Architecture ,
114+ },
115+ })
116+ if err != nil {
117+ apiError (ctx , http .StatusInternalServerError , err )
118+ return
119+ }
120+ if has {
121+ apiError (ctx , http .StatusConflict , packages_model .ErrDuplicatePackageFile )
122+ return
123+ }
124+
99125 _ , _ , err = packages_service .CreatePackageOrAddFileToExisting (
100126 ctx ,
101127 & packages_service.PackageCreationInfo {
@@ -110,7 +136,7 @@ func UploadPackageFile(ctx *context.Context) {
110136 },
111137 & packages_service.PackageFileCreationInfo {
112138 PackageFileInfo : packages_service.PackageFileInfo {
113- Filename : fmt .Sprintf ("%s-%s-%s.pck .tar.zst " , pck .Name , pck .Version , pck .FileMetadata .Architecture ),
139+ Filename : fmt .Sprintf ("%s-%s-%s.pkg .tar.%s " , pck .Name , pck .Version , pck .FileMetadata .Architecture , pck . FileCompressionExtension ),
114140 CompositeKey : fmt .Sprintf ("%s|%s" , repository , pck .FileMetadata .Architecture ),
115141 },
116142 Creator : ctx .Doer ,
@@ -144,10 +170,10 @@ func UploadPackageFile(ctx *context.Context) {
144170 ctx .Status (http .StatusCreated )
145171}
146172
147- func DownloadPackageOrRepositoryFile (ctx * context.Context ) {
148- repository := ctx .Params ("repository" )
149- architecture := ctx .Params ("architecture" )
150- filename := ctx .Params ("filename" )
173+ func GetPackageOrRepositoryFile (ctx * context.Context ) {
174+ repository := ctx .PathParam ("repository" )
175+ architecture := ctx .PathParam ("architecture" )
176+ filename := ctx .PathParam ("filename" )
151177 filenameOrig := filename
152178
153179 isSignature := strings .HasSuffix (filename , ".sig" )
@@ -231,12 +257,19 @@ func DownloadPackageOrRepositoryFile(ctx *context.Context) {
231257}
232258
233259func DeletePackageFile (ctx * context.Context ) {
234- repository , architecture := ctx .Params ("repository" ), ctx .Params ("architecture" )
260+ repository , architecture := ctx .PathParam ("repository" ), ctx .PathParam ("architecture" )
261+
262+ release , err := arch_service .AquireRegistryLock (ctx , ctx .Package .Owner .ID )
263+ if err != nil {
264+ apiError (ctx , http .StatusInternalServerError , err )
265+ return
266+ }
267+ defer release ()
235268
236269 pfs , _ , err := packages_model .SearchFiles (ctx , & packages_model.PackageFileSearchOptions {
237270 OwnerID : ctx .Package .Owner .ID ,
238271 PackageType : packages_model .TypeArch ,
239- Query : ctx .Params ("filename" ),
272+ Query : ctx .PathParam ("filename" ),
240273 CompositeKey : fmt .Sprintf ("%s|%s" , repository , architecture ),
241274 })
242275 if err != nil {
0 commit comments