Skip to content

Commit 2667260

Browse files
fix anything v4 ...
1 parent 97aefc5 commit 2667260

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
lines changed

modules/packages/arch/metadata.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,42 +262,42 @@ func ValidatePackageSpec(p *Package) error {
262262
}
263263
for _, cd := range p.VersionMetadata.CheckDepends {
264264
if !rePkgVer.MatchString(cd) {
265-
return util.NewInvalidArgumentErrorf("invalid check dependency: " + cd)
265+
return util.NewInvalidArgumentErrorf("invalid check dependency: %s", cd)
266266
}
267267
}
268268
for _, d := range p.VersionMetadata.Depends {
269269
if !rePkgVer.MatchString(d) {
270-
return util.NewInvalidArgumentErrorf("invalid dependency: " + d)
270+
return util.NewInvalidArgumentErrorf("invalid dependency: %s", d)
271271
}
272272
}
273273
for _, md := range p.VersionMetadata.MakeDepends {
274274
if !rePkgVer.MatchString(md) {
275-
return util.NewInvalidArgumentErrorf("invalid make dependency: " + md)
275+
return util.NewInvalidArgumentErrorf("invalid make dependency: %s ", md)
276276
}
277277
}
278278
for _, p := range p.VersionMetadata.Provides {
279279
if !rePkgVer.MatchString(p) {
280-
return util.NewInvalidArgumentErrorf("invalid provides: " + p)
280+
return util.NewInvalidArgumentErrorf("invalid provides: %s", p)
281281
}
282282
}
283283
for _, p := range p.VersionMetadata.Conflicts {
284284
if !rePkgVer.MatchString(p) {
285-
return util.NewInvalidArgumentErrorf("invalid conflicts: " + p)
285+
return util.NewInvalidArgumentErrorf("invalid conflicts: %s", p)
286286
}
287287
}
288288
for _, p := range p.VersionMetadata.Replaces {
289289
if !rePkgVer.MatchString(p) {
290-
return util.NewInvalidArgumentErrorf("invalid replaces: " + p)
290+
return util.NewInvalidArgumentErrorf("invalid replaces: %s", p)
291291
}
292292
}
293293
for _, p := range p.VersionMetadata.Replaces {
294294
if !rePkgVer.MatchString(p) {
295-
return util.NewInvalidArgumentErrorf("invalid xdata: " + p)
295+
return util.NewInvalidArgumentErrorf("invalid xdata: %s", p)
296296
}
297297
}
298298
for _, od := range p.VersionMetadata.OptDepends {
299299
if !reOptDep.MatchString(od) {
300-
return util.NewInvalidArgumentErrorf("invalid optional dependency: " + od)
300+
return util.NewInvalidArgumentErrorf("invalid optional dependency: %s", od)
301301
}
302302
}
303303
for _, bf := range p.VersionMetadata.Backup {

routers/api/packages/api.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,20 @@ func CommonRoutes() *web.Router {
159159
arch.PushPackage(ctx)
160160
return
161161
} else if isDelete {
162-
if groupLen < 2 {
162+
if groupLen < 3 {
163163
ctx.Status(http.StatusBadRequest)
164164
return
165165
}
166-
if groupLen == 2 {
166+
if groupLen == 3 {
167167
ctx.SetPathParam("group", "")
168168
ctx.SetPathParam("package", pathGroups[0])
169169
ctx.SetPathParam("version", pathGroups[1])
170+
ctx.SetPathParam("arch", pathGroups[2])
170171
} else {
171-
ctx.SetPathParam("group", strings.Join(pathGroups[:groupLen-2], "/"))
172-
ctx.SetPathParam("package", pathGroups[groupLen-2])
173-
ctx.SetPathParam("version", pathGroups[groupLen-1])
172+
ctx.SetPathParam("group", strings.Join(pathGroups[:groupLen-3], "/"))
173+
ctx.SetPathParam("package", pathGroups[groupLen-3])
174+
ctx.SetPathParam("version", pathGroups[groupLen-2])
175+
ctx.SetPathParam("arch", pathGroups[groupLen-1])
174176
}
175177
reqPackageAccess(perm.AccessModeWrite)(ctx)
176178
if ctx.Written() {

routers/api/packages/arch/arch.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"net/http"
12+
"path/filepath"
1213
"regexp"
1314
"strings"
1415

@@ -208,9 +209,10 @@ func GetPackageOrDB(ctx *context.Context) {
208209

209210
func RemovePackage(ctx *context.Context) {
210211
var (
211-
group = ctx.PathParam("group")
212-
pkg = ctx.PathParam("package")
213-
ver = ctx.PathParam("version")
212+
group = ctx.PathParam("group")
213+
pkg = ctx.PathParam("package")
214+
ver = ctx.PathParam("version")
215+
pkgArch = ctx.PathParam("arch")
214216
)
215217
pv, err := packages_model.GetVersionByNameAndVersion(
216218
ctx, ctx.Package.Owner.ID, packages_model.TypeArch, pkg, ver,
@@ -230,7 +232,13 @@ func RemovePackage(ctx *context.Context) {
230232
}
231233
deleted := false
232234
for _, file := range files {
233-
if file.CompositeKey == group {
235+
extName := fmt.Sprintf("-%s.pkg.tar%s", pkgArch, filepath.Ext(file.LowerName))
236+
if strings.HasSuffix(file.LowerName, ".sig") {
237+
extName = fmt.Sprintf("-%s.pkg.tar%s.sig", pkgArch,
238+
filepath.Ext(strings.TrimSuffix(file.LowerName, filepath.Ext(file.LowerName))))
239+
}
240+
if file.CompositeKey == group &&
241+
strings.HasSuffix(file.LowerName, extName) {
234242
deleted = true
235243
err := packages_service.RemovePackageFileAndVersionIfUnreferenced(ctx, ctx.ContextUser, file)
236244
if err != nil {

tests/integration/api_packages_arch_test.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,24 +258,38 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
258258
AddBasicAuth(user.Name)
259259
MakeRequest(t, req, http.StatusCreated)
260260

261-
req = NewRequestWithBody(t, "DELETE", rootURL+"/base/notfound/1.0.0-1", nil).
261+
req = NewRequestWithBody(t, "DELETE", rootURL+"/base/notfound/1.0.0-1/any", nil).
262262
AddBasicAuth(user.Name)
263263
MakeRequest(t, req, http.StatusNotFound)
264264

265-
req = NewRequestWithBody(t, "DELETE", groupURL+"/test/1.0.0-1", nil).
265+
req = NewRequestWithBody(t, "DELETE", groupURL+"/test/1.0.0-1/x86_64", nil).
266+
AddBasicAuth(user.Name)
267+
MakeRequest(t, req, http.StatusNoContent)
268+
269+
req = NewRequestWithBody(t, "DELETE", groupURL+"/test/1.0.0-1/any", nil).
266270
AddBasicAuth(user.Name)
267271
MakeRequest(t, req, http.StatusNoContent)
268272

269273
req = NewRequest(t, "GET", groupURL+"/x86_64/base.db")
270274
respPkg := MakeRequest(t, req, http.StatusOK)
271275
files, err := listTarGzFiles(respPkg.Body.Bytes())
272276
require.NoError(t, err)
273-
require.Len(t, files, 1) // other pkg in L225
277+
require.Len(t, files, 1)
274278

275-
req = NewRequestWithBody(t, "DELETE", groupURL+"/test2/1.0.0-1", nil).
279+
req = NewRequestWithBody(t, "DELETE", groupURL+"/test2/1.0.0-1/any", nil).
276280
AddBasicAuth(user.Name)
277281
MakeRequest(t, req, http.StatusNoContent)
278-
req = NewRequest(t, "GET", groupURL+"/x86_64/base.db")
282+
283+
req = NewRequest(t, "GET", groupURL+"/x86_64/base.db").
284+
AddBasicAuth(user.Name)
285+
MakeRequest(t, req, http.StatusNotFound)
286+
287+
req = NewRequestWithBody(t, "DELETE", groupURL+"/test/1.0.0-1/aarch64", nil).
288+
AddBasicAuth(user.Name)
289+
MakeRequest(t, req, http.StatusNoContent)
290+
291+
req = NewRequest(t, "GET", groupURL+"/aarch64/base.db").
292+
AddBasicAuth(user.Name)
279293
MakeRequest(t, req, http.StatusNotFound)
280294
})
281295

@@ -294,7 +308,7 @@ HMhNSS1IzUsBcpJAPFAwwUXSM0u4BjoaR8EoGAWjgGQAAILFeyQADAAA
294308
resp := MakeRequest(t, req, http.StatusOK)
295309
require.Equal(t, pkgs[key], resp.Body.Bytes())
296310

297-
req = NewRequestWithBody(t, "DELETE", groupURL+"/test2/1.0.0-1", nil).
311+
req = NewRequestWithBody(t, "DELETE", groupURL+"/test2/1.0.0-1/any", nil).
298312
AddBasicAuth(user.Name)
299313
MakeRequest(t, req, http.StatusNoContent)
300314
})

0 commit comments

Comments
 (0)