99	"fmt" 
1010	"io" 
1111	"net/http" 
12+ 	"regexp" 
1213	"strings" 
1314
1415	packages_model "code.gitea.io/gitea/models/packages" 
@@ -21,6 +22,11 @@ import (
2122	arch_service "code.gitea.io/gitea/services/packages/arch" 
2223)
2324
25+ var  (
26+ 	archPkgOrSig  =  regexp .MustCompile (`^.*\.pkg\.tar\.\w+(\.sig)*$` )
27+ 	archDBOrSig   =  regexp .MustCompile (`^.*.db(\.tar\.gz)*(\.sig)*$` )
28+ )
29+ 
2430func  apiError (ctx  * context.Context , status  int , obj  any ) {
2531	helper .LogAndProcessError (ctx , status , obj , func (message  string ) {
2632		ctx .PlainText (status , message )
@@ -41,7 +47,7 @@ func GetRepositoryKey(ctx *context.Context) {
4147}
4248
4349func  PushPackage (ctx  * context.Context ) {
44- 	distro  :=  ctx .PathParam ("distro " )
50+ 	group  :=  ctx .PathParam ("group " )
4551
4652	upload , needToClose , err  :=  ctx .UploadStream ()
4753	if  err  !=  nil  {
@@ -61,7 +67,7 @@ func PushPackage(ctx *context.Context) {
6167
6268	p , err  :=  arch_module .ParsePackage (buf )
6369	if  err  !=  nil  {
64- 		apiError (ctx , http .StatusInternalServerError , err )
70+ 		apiError (ctx , http .StatusBadRequest , err )
6571		return 
6672	}
6773
@@ -97,7 +103,7 @@ func PushPackage(ctx *context.Context) {
97103	properties  :=  map [string ]string {
98104		arch_module .PropertyDescription :  p .Desc (),
99105		arch_module .PropertyArch :         p .FileMetadata .Arch ,
100- 		arch_module .PropertyDistribution : distro ,
106+ 		arch_module .PropertyDistribution : group ,
101107	}
102108
103109	version , _ , err  :=  packages_service .CreatePackageOrAddFileToExisting (
@@ -114,8 +120,8 @@ func PushPackage(ctx *context.Context) {
114120		},
115121		& packages_service.PackageFileCreationInfo {
116122			PackageFileInfo : packages_service.PackageFileInfo {
117- 				Filename :     fmt .Sprintf ("%s-%s-%s.pkg.tar.zst " , p .Name , p .Version , p .FileMetadata .Arch ),
118- 				CompositeKey : distro ,
123+ 				Filename :     fmt .Sprintf ("%s-%s-%s.pkg.tar.%s " , p .Name , p .Version , p .FileMetadata .Arch ,  p . CompressType ),
124+ 				CompositeKey : group ,
119125			},
120126			OverwriteExisting : false ,
121127			IsLead :            true ,
@@ -138,8 +144,8 @@ func PushPackage(ctx *context.Context) {
138144	// add sign file 
139145	_ , err  =  packages_service .AddFileToPackageVersionInternal (ctx , version , & packages_service.PackageFileCreationInfo {
140146		PackageFileInfo : packages_service.PackageFileInfo {
141- 			CompositeKey : distro ,
142- 			Filename :     fmt .Sprintf ("%s-%s-%s.pkg.tar.zst .sig" , p .Name , p .Version , p .FileMetadata .Arch ),
147+ 			CompositeKey : group ,
148+ 			Filename :     fmt .Sprintf ("%s-%s-%s.pkg.tar.%s .sig" , p .Name , p .Version , p .FileMetadata .Arch ,  p . CompressType ),
143149		},
144150		OverwriteExisting : true ,
145151		IsLead :            false ,
@@ -149,7 +155,7 @@ func PushPackage(ctx *context.Context) {
149155	if  err  !=  nil  {
150156		apiError (ctx , http .StatusInternalServerError , err )
151157	}
152- 	if  err  =  arch_service .BuildPacmanDB (ctx , ctx .Package .Owner .ID , distro , p .FileMetadata .Arch ); err  !=  nil  {
158+ 	if  err  =  arch_service .BuildPacmanDB (ctx , ctx .Package .Owner .ID , group , p .FileMetadata .Arch ); err  !=  nil  {
153159		apiError (ctx , http .StatusInternalServerError , err )
154160		return 
155161	}
@@ -158,13 +164,13 @@ func PushPackage(ctx *context.Context) {
158164
159165func  GetPackageOrDB (ctx  * context.Context ) {
160166	var  (
161- 		file     =  ctx .PathParam ("file" )
162- 		distro  =  ctx .PathParam ("distro " )
163- 		arch     =  ctx .PathParam ("arch" )
167+ 		file   =  ctx .PathParam ("file" )
168+ 		group  =  ctx .PathParam ("group " )
169+ 		arch   =  ctx .PathParam ("arch" )
164170	)
165171
166- 	if  strings . HasSuffix (file ,  ".pkg.tar.zst" )  ||   strings . HasSuffix ( file ,  ".pkg.tar.zst.sig" ) {
167- 		pkg , err  :=  arch_service .GetPackageFile (ctx , distro , file , ctx .Package .Owner .ID )
172+ 	if  archPkgOrSig . MatchString (file ) {
173+ 		pkg , err  :=  arch_service .GetPackageFile (ctx , group , file , ctx .Package .Owner .ID )
168174		if  err  !=  nil  {
169175			if  errors .Is (err , util .ErrNotExist ) {
170176				apiError (ctx , http .StatusNotFound , err )
@@ -180,11 +186,8 @@ func GetPackageOrDB(ctx *context.Context) {
180186		return 
181187	}
182188
183- 	if  strings .HasSuffix (file , ".db.tar.gz" ) || 
184- 		strings .HasSuffix (file , ".db" ) || 
185- 		strings .HasSuffix (file , ".db.tar.gz.sig" ) || 
186- 		strings .HasSuffix (file , ".db.sig" ) {
187- 		pkg , err  :=  arch_service .GetPackageDBFile (ctx , distro , arch , ctx .Package .Owner .ID ,
189+ 	if  archDBOrSig .MatchString (file ) {
190+ 		pkg , err  :=  arch_service .GetPackageDBFile (ctx , group , arch , ctx .Package .Owner .ID ,
188191			strings .HasSuffix (file , ".sig" ))
189192		if  err  !=  nil  {
190193			if  errors .Is (err , util .ErrNotExist ) {
@@ -205,9 +208,9 @@ func GetPackageOrDB(ctx *context.Context) {
205208
206209func  RemovePackage (ctx  * context.Context ) {
207210	var  (
208- 		distro  =  ctx .PathParam ("distro " )
209- 		pkg      =  ctx .PathParam ("package" )
210- 		ver      =  ctx .PathParam ("version" )
211+ 		group  =  ctx .PathParam ("group " )
212+ 		pkg    =  ctx .PathParam ("package" )
213+ 		ver    =  ctx .PathParam ("version" )
211214	)
212215	pv , err  :=  packages_model .GetVersionByNameAndVersion (
213216		ctx , ctx .Package .Owner .ID , packages_model .TypeArch , pkg , ver ,
@@ -227,7 +230,7 @@ func RemovePackage(ctx *context.Context) {
227230	}
228231	deleted  :=  false 
229232	for  _ , file  :=  range  files  {
230- 		if  file .CompositeKey  ==  distro  {
233+ 		if  file .CompositeKey  ==  group  {
231234			deleted  =  true 
232235			err  :=  packages_service .RemovePackageFileAndVersionIfUnreferenced (ctx , ctx .ContextUser , file )
233236			if  err  !=  nil  {
@@ -237,7 +240,7 @@ func RemovePackage(ctx *context.Context) {
237240		}
238241	}
239242	if  deleted  {
240- 		err  =  arch_service .BuildCustomRepositoryFiles (ctx , ctx .Package .Owner .ID , distro )
243+ 		err  =  arch_service .BuildCustomRepositoryFiles (ctx , ctx .Package .Owner .ID , group )
241244		if  err  !=  nil  {
242245			apiError (ctx , http .StatusInternalServerError , err )
243246		}
0 commit comments