loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'Feat: Add support for `pacman -F` in Arch package' (#6180) from dragon/forgejo:clear-arch-pkg into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6180
Reviewed-by: Gusted <gusted@noreply.codeberg.org>

+96 -29
+23 -2
modules/packages/arch/metadata.go
··· 4 4 package arch 5 5 6 6 import ( 7 + "archive/tar" 7 8 "bufio" 8 9 "bytes" 9 10 "encoding/hex" ··· 25 26 // https://man.archlinux.org/man/PKGBUILD.5 26 27 27 28 const ( 28 - PropertyDescription = "arch.description" 29 + PropertyDescription = "arch.description" 30 + PropertyFiles = "arch.files" 31 + 29 32 PropertyArch = "arch.architecture" 30 33 PropertyDistribution = "arch.distribution" 31 34 ··· 85 88 Packager string `json:"packager"` 86 89 Arch string `json:"arch"` 87 90 PgpSigned string `json:"pgp"` 91 + 92 + Files []string `json:"files,omitempty"` 88 93 } 89 94 90 95 // ParsePackage Function that receives arch package archive data and returns it's metadata. ··· 127 132 var pkg *Package 128 133 var mTree bool 129 134 135 + files := make([]string, 0) 136 + 130 137 for { 131 138 f, err := tarball.Read() 132 139 if err == io.EOF { ··· 135 142 if err != nil { 136 143 return nil, err 137 144 } 145 + // ref:https://gitlab.archlinux.org/pacman/pacman/-/blob/91546004903eea5d5267d59898a6029ba1d64031/lib/libalpm/add.c#L529-L533 146 + if !strings.HasPrefix(f.Name(), ".") { 147 + files = append(files, (f.Header.(*tar.Header)).Name) 148 + } 149 + 138 150 switch f.Name() { 139 151 case ".PKGINFO": 140 152 pkg, err = ParsePackageInfo(tarballType, f) ··· 155 167 if !mTree { 156 168 return nil, util.NewInvalidArgumentErrorf(".MTREE file not found") 157 169 } 158 - 170 + pkg.FileMetadata.Files = files 159 171 pkg.FileMetadata.CompressedSize = r.Size() 160 172 pkg.FileMetadata.MD5 = hex.EncodeToString(md5) 161 173 pkg.FileMetadata.SHA256 = hex.EncodeToString(sha256) ··· 339 351 } 340 352 return buf.String() 341 353 } 354 + 355 + func (p *Package) Files() string { 356 + var buf bytes.Buffer 357 + buf.WriteString("%FILES%\n") 358 + for _, item := range p.FileMetadata.Files { 359 + _, _ = fmt.Fprintf(&buf, "%s\n", item) 360 + } 361 + return buf.String() 362 + }
+11 -3
modules/packages/arch/metadata_test.go
··· 344 344 }) 345 345 } 346 346 347 - func TestDescString(t *testing.T) { 348 - const pkgdesc = `%FILENAME% 347 + func TestDescAndFileString(t *testing.T) { 348 + const pkgDesc = `%FILENAME% 349 349 zstd-1.5.5-1-x86_64.pkg.tar.zst 350 350 351 351 %NAME% ··· 417 417 418 418 ` 419 419 420 + const pkgFiles = `%FILES% 421 + usr/ 422 + usr/bin/ 423 + usr/bin/zstd 424 + ` 425 + 420 426 md := &Package{ 421 427 CompressType: "zst", 422 428 Name: "zstd", ··· 441 447 BuildDate: 1681646714, 442 448 Packager: "Jelle van der Waa <jelle@archlinux.org>", 443 449 Arch: "x86_64", 450 + Files: []string{"usr/", "usr/bin/", "usr/bin/zstd"}, 444 451 }, 445 452 } 446 - require.Equal(t, pkgdesc, md.Desc()) 453 + require.Equal(t, pkgDesc, md.Desc()) 454 + require.Equal(t, pkgFiles, md.Files()) 447 455 }
+2 -1
routers/api/packages/arch/arch.go
··· 26 26 27 27 var ( 28 28 archPkgOrSig = regexp.MustCompile(`^.*\.pkg\.tar\.\w+(\.sig)*$`) 29 - archDBOrSig = regexp.MustCompile(`^.*.db(\.tar\.gz)*(\.sig)*$`) 29 + archDBOrSig = regexp.MustCompile(`^.*.(db|files)(\.tar\.gz)*(\.sig)*$`) 30 30 31 31 locker = sync.NewExclusivePool() 32 32 ) ··· 115 115 116 116 properties := map[string]string{ 117 117 arch_module.PropertyDescription: p.Desc(), 118 + arch_module.PropertyFiles: p.Files(), 118 119 arch_module.PropertyArch: p.FileMetadata.Arch, 119 120 arch_module.PropertyDistribution: group, 120 121 }
+29 -7
services/packages/arch/repository.go
··· 225 225 if err != nil { 226 226 return nil, err 227 227 } 228 - if len(pps) >= 1 { 229 - meta := []byte(pps[0].Value) 228 + if len(pps) == 0 { 229 + continue 230 + } 231 + pkgDesc := []byte(pps[0].Value) 232 + header := &tar.Header{ 233 + Name: pkg.Name + "-" + ver.Version + "/desc", 234 + Size: int64(len(pkgDesc)), 235 + Mode: int64(os.ModePerm), 236 + } 237 + if err = tw.WriteHeader(header); err != nil { 238 + return nil, err 239 + } 240 + if _, err := tw.Write(pkgDesc); err != nil { 241 + return nil, err 242 + } 243 + 244 + pfs, err := packages_model.GetPropertiesByName( 245 + ctx, packages_model.PropertyTypeFile, pf.ID, arch_module.PropertyFiles, 246 + ) 247 + if err != nil { 248 + return nil, err 249 + } 250 + if len(pfs) >= 1 { 251 + pkgFiles := []byte(pfs[0].Value) 230 252 header := &tar.Header{ 231 - Name: pkg.Name + "-" + ver.Version + "/desc", 232 - Size: int64(len(meta)), 253 + Name: pkg.Name + "-" + ver.Version + "/files", 254 + Size: int64(len(pkgFiles)), 233 255 Mode: int64(os.ModePerm), 234 256 } 235 257 if err = tw.WriteHeader(header); err != nil { 236 258 return nil, err 237 259 } 238 - if _, err := tw.Write(meta); err != nil { 260 + if _, err := tw.Write(pkgFiles); err != nil { 239 261 return nil, err 240 262 } 241 - count++ 242 - break 243 263 } 264 + count++ 265 + break 244 266 } 245 267 } 246 268 if count == 0 {
+31 -16
tests/integration/api_packages_arch_test.go
··· 223 223 224 224 t.Run(fmt.Sprintf("RepositoryDB[%s]", group), func(t *testing.T) { 225 225 defer tests.PrintCurrentTest(t)() 226 - req := NewRequest(t, "GET", rootURL+"/repository.key") 227 - respPub := MakeRequest(t, req, http.StatusOK) 226 + req := NewRequest(t, "GET", groupURL+"/x86_64/base.db.tar.gz") 227 + MakeRequest(t, req, http.StatusOK) 228 + 229 + req = NewRequest(t, "GET", groupURL+"/x86_64/base.files") 230 + MakeRequest(t, req, http.StatusOK) 231 + 232 + req = NewRequest(t, "GET", groupURL+"/x86_64/base.files.tar.gz") 233 + MakeRequest(t, req, http.StatusOK) 228 234 229 235 req = NewRequest(t, "GET", groupURL+"/x86_64/base.db") 230 236 respPkg := MakeRequest(t, req, http.StatusOK) ··· 232 238 req = NewRequest(t, "GET", groupURL+"/x86_64/base.db.sig") 233 239 respSig := MakeRequest(t, req, http.StatusOK) 234 240 241 + req = NewRequest(t, "GET", rootURL+"/repository.key") 242 + respPub := MakeRequest(t, req, http.StatusOK) 243 + 235 244 if err := gpgVerify(respPub.Body.Bytes(), respSig.Body.Bytes(), respPkg.Body.Bytes()); err != nil { 236 245 t.Fatal(err) 237 246 } 238 247 files, err := listTarGzFiles(respPkg.Body.Bytes()) 239 248 require.NoError(t, err) 240 - require.Len(t, files, 1) 249 + require.Len(t, files, 2) 241 250 for s, d := range files { 242 - name := getProperty(string(d.Data), "NAME") 243 - ver := getProperty(string(d.Data), "VERSION") 244 - require.Equal(t, name+"-"+ver+"/desc", s) 245 - fn := getProperty(string(d.Data), "FILENAME") 246 - pgp := getProperty(string(d.Data), "PGPSIG") 247 - req = NewRequest(t, "GET", groupURL+"/x86_64/"+fn+".sig") 248 - respSig := MakeRequest(t, req, http.StatusOK) 249 - decodeString, err := base64.StdEncoding.DecodeString(pgp) 250 - require.NoError(t, err) 251 - require.Equal(t, respSig.Body.Bytes(), decodeString) 251 + if strings.HasSuffix(s, "/desc") { 252 + name := getProperty(string(d.Data), "NAME") 253 + ver := getProperty(string(d.Data), "VERSION") 254 + require.Equal(t, name+"-"+ver+"/desc", s) 255 + fn := getProperty(string(d.Data), "FILENAME") 256 + pgp := getProperty(string(d.Data), "PGPSIG") 257 + req = NewRequest(t, "GET", groupURL+"/x86_64/"+fn+".sig") 258 + respSig := MakeRequest(t, req, http.StatusOK) 259 + decodeString, err := base64.StdEncoding.DecodeString(pgp) 260 + require.NoError(t, err) 261 + require.Equal(t, respSig.Body.Bytes(), decodeString) 262 + } else if strings.HasSuffix(s, "/files") { 263 + require.True(t, strings.HasPrefix(string(d.Data), "%FILES%")) 264 + } else { 265 + require.Failf(t, "unknown item", "fileName:%s", s) 266 + } 252 267 } 253 268 }) 254 269 ··· 275 290 respPkg := MakeRequest(t, req, http.StatusOK) 276 291 files, err := listTarGzFiles(respPkg.Body.Bytes()) 277 292 require.NoError(t, err) 278 - require.Len(t, files, 1) 293 + require.Len(t, files, 2) 279 294 280 295 req = NewRequestWithBody(t, "DELETE", groupURL+"/test2/1.0.0-1/any", nil). 281 296 AddBasicAuth(user.Name) ··· 347 362 348 363 files, err := listTarGzFiles(respPkg.Body.Bytes()) 349 364 require.NoError(t, err) 350 - require.Len(t, files, 1) 365 + require.Len(t, files, 2) 351 366 352 367 req = NewRequestWithBody(t, "PUT", rootURL, bytes.NewReader(pkgs["otherXZ"])). 353 368 AddBasicAuth(user.Name) ··· 358 373 359 374 files, err = listTarGzFiles(respPkg.Body.Bytes()) 360 375 require.NoError(t, err) 361 - require.Len(t, files, 2) 376 + require.Len(t, files, 4) 362 377 }) 363 378 } 364 379