-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Arch packages implementation #25396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Arch packages implementation #25396
Changes from 10 commits
Commits
Show all changes
187 commits
Select commit
Hold shift + click to select a range
ec18d9b
added arch packages implementation
d24e41a
fixed db download failure and incorrect package owner assigned on push
6ec9686
updated icon name and centered viewbox
4811ebc
Merge branch 'main' into pacman-packages
silverwind 6328a92
generated optimized svg arch icon
808a7ae
replaced zstd with archiver and limit reader to speed up metadata eje…
b354f02
code refactoring and package version publisher id correction
af99efb
moved arch package routes to the same scope with other packages
e75ddfd
reused existing services/packages functions for package and signature…
ae79dbd
package UI corrections
a5784f6
Update web_src/svg/octicon-arch.svg
f31e52d
corrected arch icon reference and optimization
41667b2
changed signature verification library to reuse existing dependency
e399ce8
opdated operation pacman database craetion to form or update database…
e2b12f2
fixed error when attempting to read empty database
c372311
corrected package database connection description and documentation r…
5beeb24
added method to remove package verified with user's GPG key, removed …
04a3ddd
changed function retrieving package version when deleting package ver…
749a106
updated remove function description
1d1a5a3
added function removing old package entries from pacman database to a…
f1fae9a
changed procedure of package metadata ejection, removed unnecessary f…
39e42f7
fixed dependencies appended to wrong field in metadata
6ac2815
Merge branch 'main' into pacman-packages
2873deb
documentation for arch packages, additional signature in arch package…
b42b8c5
Merge branch 'main' into pacman-packages
6532fe0
Merge branch 'go-gitea:main' into pacman-packages
3ffb4b2
Merge branch 'main' into pacman-packages
silverwind 6d1037d
db desc file for pacman database is saved in the same space with package
56772de
corrected package blob structure, pacman database is created on get r…
0ed4d0c
Merge branch 'main' into pacman-packages
6d7c770
build date, installed and compressed size UI view
568c3b1
test for package create, get and delete operations
b5db5b8
Merge branch 'main' into pacman-packages
silverwind 176b09b
Merge branch 'go-gitea:main' into pacman-packages
d8623be
added test printing after execution
f0d569c
Merge branch 'go-gitea:main' into pacman-packages
364c33b
fixed pacman database creation error for case with multiple architect…
b5218eb
Merge branch 'go-gitea:main' into pacman-packages
38024b5
time mocked for arch package unit tests
da5c7c2
created user with gpg token in arch package tests
2685f1a
Merge branch 'main' into pacman-packages
silverwind 1df0a1d
fixed file size for mock and scope of time patch
f912dd6
corrected tests, added test cases for databases with different archit…
73fe874
Merge branch 'go-gitea:main' into pacman-packages
8195185
lint corrections
f3841f0
fixed response status code for metadata update operation
d679c7e
Merge branch 'main' into pacman-packages
c4f3fb3
markdown and code documentation lint corrections
1e16783
Merge branch 'main' into pacman-packages
c20e1e0
temporarily removed dependency for time mock in tests
1a08290
Merge branch 'main' into pacman-packages
baf3a03
fixed dependency for time mocks in integration tests for arch linux p…
8d691f0
Merge branch 'main' into pacman-packages
silverwind e24db36
fixed version order when creating pacman database for package with mu…
9e7c6ef
updated documentation about metadata update function
1ea4d48
fixed package version owner in metadata update operation
faff9d9
getting storage object instead of reading bytes
245a545
Merge branch 'main' into pacman-packages
597a948
replaced custom auth with existing methods
542882d
fixed tests, corrected documentation
cdc5107
corrected SigLevel value for pacman database connection in documentation
0093004
removed distro field from arch package metadata, corrected related UI
0632f57
lint corrections
67bd2bc
simplified push in docs, corrected pkg UI
23f1ba1
replaced base domain variable in metadata with registry host variable…
e22a3c7
Merge branch 'main' into pacman-packages
aec1780
arch icon lint fix
672b00b
Merge branch 'main' into pacman-packages
silverwind 523e826
Merge branch 'main' into pacman-packages
b13e3d3
Merge branch 'main' into pacman-packages
749a873
Merge branch 'go-gitea:main' into pacman-packages
59bf7a7
changed mirrors, documentation location
ab1a9a1
changed context doer to context user, fixed package config setting
ce0d393
removed unnecessary headers in arch package template
9543262
removed unused package size limit
3cef8c6
corrected title in documentation
1abff64
refactoring function to find unique values
7b92529
Update routers/api/packages/arch/arch.go
524a2a0
Update routers/api/packages/arch/arch.go
1e33f61
Update routers/api/packages/arch/arch.go
8b06f76
replaced HTTP headers with url params
730cbb1
dynamic architecture and distribution in arch repo link
3df8d52
changed pacman database creation mechanics, storing package desc as f…
5e4c582
Merge branch 'main' into pacman-packages
3c6dd37
Merge branch 'main' into pacman-packages
f422942
fixed mechanics of pacman database creation
a15a924
Merge branch 'main' into pacman-packages
d069303
fixed pacman database creation algorithm, arch UI template
a95453b
Merge branch 'main' into pacman-packages
d2d8aa7
documentation fixes
fdd807d
Merge branch 'main' into pacman-packages
bfe6b37
reduced package size in tests, additional tests to verify package sig…
e01ac83
documentation corrections
ebaa543
lint corrections
0c7aa7f
refactoring
1c0a0e2
Merge branch 'main' into pacman-packages
a45be30
Merge branch 'main' into pacman-packages
28712bc
refactoring
a3cb45c
Merge branch 'main' into pacman-packages
02dcce8
Merge branch 'main' into pacman-packages
2548414
Merge branch 'main' into pacman-packages
e86bdfc
metadata and signature are stored in package properties instead of ob…
0d08eaa
reduced amount of logic, removed unnecessary fields
27fa815
fixed database creation procedure for packages with any architecture
c311ec2
Merge branch 'main' into pacman-packages
4a40107
Merge branch 'main' into pacman-packages
a702734
Merge branch 'main' into pacman-packages
ccccfae
Merge branch 'main' into pacman-packages
9273dc0
removed AUR helpers from arch package manager list
065d134
Merge branch 'main' into pacman-packages
8604494
Merge branch 'main' into pacman-packages
eb7f51a
Merge branch 'main' into pacman-packages
ce01499
removed/corrected some documentation
ad2af70
Merge branch 'main' into pacman-packages
93b1f85
Merge branch 'main' into pacman-packages
431dabf
fixed procedure of retrieving package properties for signatures and p…
70effa2
Merge branch 'go-gitea:main' into pacman-packages
934d119
Merge branch 'go-gitea:main' into pacman-packages
f914c93
Merge branch 'go-gitea:main' into pacman-packages
7c2d1b3
fixed package key when getting any architecture
429477e
Merge branch 'main' into pacman-packages
a2aaae3
refactoring funciton creating arch package database archive
a4d878c
Merge branch 'go-gitea:main' into pacman-packages
1b4b03d
Merge branch 'main' into pacman-packages
17f02ce
Merge branch 'main' into pacman-packages
8faea42
Merge branch 'main' into pacman-packages
d7bd108
Update models/packages/package_file.go
6005281
fix request permission access position for push/remove handlers
a9a5b7a
service method to get package file stream
54fd84d
function to get package file property by composite key, refactoring f…
907aa02
refactoring create pacman database function
946d8cc
Merge branch 'main' into pacman-packages
4656b3b
replaced bytes.Buffer with packages.HashedBuffer to return working io…
0dd3db2
fixed user in package upload operation
c09da2a
removed functionality related to automatic source code repository con…
a1ee2a0
Merge branch 'main' into pacman-packages
ba92fc5
pass context to package service methods
fcb3fd1
corrected procedure of retrieving package file property to package ow…
f515f6e
removed unnecessary filename from composite key
4bf84c1
corrected arch template and related locale options
8974d27
refactoring in metadata module, better readability
784b4f9
refactoring in metadata module, pacman database creation function
33ae3bd
Merge branch 'main' into pacman-packages
94f45f4
change interface{} to any, move apiError function to bottom
d473e01
fixed pacman database creation process, corrected switch to next entr…
b7725c6
formatting corrections
54c0816
refactoring, better readability in arch package metadata module
26e5f9e
Merge branch 'main' into pacman-packages
b63af7e
metadata tests, json struct tag unification with other linux packages…
99f856a
Merge branch 'main' into pacman-packages
thionic 54a9c8b
corrected response codes in push and remove operations
thionic 6052aea
moved upload function to arch service
thionic f812aa7
fixes in arch package metadata tests
thionic 95a1df6
import naming unification with other package types
thionic fe9086b
Merge branch 'main' into pacman-packages
thionic 52a5c61
Merge branch 'main' into pacman-packages
thionic f8b78cb
Merge branch 'main' into pacman-packages
thionic 8aeada8
additional validations for package metadata fields, split package met…
thionic 5becd3c
initialize regular expressions for arch package validation once
thionic 73aef3a
integration tests for databases with different architectures, versio…
thionic 1840207
refactoring arch package integration tests
thionic 6652fba
remove endpoint tests
thionic 5c22b91
lint corrections
thionic 45c86cc
Merge branch 'main' into pacman-packages
thionic 1e972d7
unified approach to compare pacman databases (independed from archive…
thionic fc8f807
comparison of pacman database entries in integration tests
thionic 42587dd
Merge branch 'main' into pacman-packages
thionic d6a05c3
moved package properties to constants in metadata module
thionic ca66c6d
use buffer in pacman db desc function
thionic c9abcf9
error message clarification, typo fix in integration tests
thionic 11bc5f6
Update docs/content/usage/packages/arch.en-us.md
1d168c6
Update docs/content/usage/packages/arch.en-us.md
8d0e301
Update docs/content/usage/packages/arch.en-us.md
d42e381
Update docs/content/usage/packages/arch.en-us.md
373d904
Update docs/content/usage/packages/arch.en-us.md
16da9f9
Update docs/content/usage/packages/arch.en-us.md
ffca863
moved link to arch package documentation from translation to html tem…
thionic 4b96ddd
Update web_src/svg/gitea-arch.svg
a054f02
fixed context references in arch package html templates, removed URL …
thionic d234b66
translations for arch metadata fields
thionic d9080be
Merge branch 'main' into pacman-packages
silverwind 4ba0567
fix arch linux icon
thionic b12de2a
integration tests fixes and enhancements: isolated tests for differen…
thionic b97d4f9
fix: context doer as package creator
thionic a4af98e
Merge branch 'main' into pacman-packages
thionic 9202199
Merge branch 'main' into pacman-packages
thionic feb99cd
Merge branch 'main' into pacman-packages
thionic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package arch | ||
|
||
import ( | ||
"bytes" | ||
"crypto/md5" | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"io/fs" | ||
"os" | ||
"path" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/mholt/archiver/v3" | ||
) | ||
|
||
// Metadata for arch package. | ||
type Metadata struct { | ||
Filename string | ||
Name string | ||
Base string | ||
Version string | ||
Description string | ||
CompressedSize int64 | ||
CompressedSizeMib string | ||
InstalledSize int64 | ||
InstalledSizeMib string | ||
MD5 string | ||
SHA256 string | ||
URL string | ||
BuildDate int64 | ||
BuildDateStr string | ||
BaseDomain string | ||
Packager string | ||
Provides []string | ||
License []string | ||
Arch []string | ||
Depends []string | ||
OptDepends []string | ||
MakeDepends []string | ||
CheckDepends []string | ||
Backup []string | ||
} | ||
|
||
// Function that recieves arch package archive data and returns it's metadata. | ||
func EjectMetadata(filename, domain string, pkg []byte) (*Metadata, error) { | ||
pkgreader := io.LimitReader(bytes.NewReader(pkg), 250000) | ||
var buf bytes.Buffer | ||
err := archiver.DefaultZstd.Decompress(pkgreader, &buf) | ||
if err != nil { | ||
if !errors.Is(err, io.ErrUnexpectedEOF) { | ||
return nil, err | ||
} | ||
} | ||
splt := strings.Split(buf.String(), "PKGINFO") | ||
if len(splt) < 2 { | ||
return nil, errors.New("unable to eject .PKGINFO from archive") | ||
} | ||
raw := splt[1][0:10000] | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
inssize := int64(len(pkg)) | ||
compsize := ejectInt64(raw, "size") | ||
unixbuilddate := ejectInt64(raw, "builddate") | ||
return &Metadata{ | ||
Filename: filename, | ||
Name: ejectString(raw, "pkgname"), | ||
Base: ejectString(raw, "pkgbase"), | ||
Version: ejectString(raw, "pkgver"), | ||
Description: ejectString(raw, "pkgdesc"), | ||
CompressedSize: inssize, | ||
CompressedSizeMib: ByteCountSI(inssize), | ||
InstalledSize: compsize, | ||
InstalledSizeMib: ByteCountSI(compsize), | ||
MD5: md5sum(pkg), | ||
SHA256: sha256sum(pkg), | ||
URL: ejectString(raw, "url"), | ||
BuildDate: unixbuilddate, | ||
BuildDateStr: ReadableTime(unixbuilddate), | ||
BaseDomain: domain, | ||
Packager: ejectString(raw, "packager"), | ||
Provides: ejectStrings(raw, "provides"), | ||
License: ejectStrings(raw, "license"), | ||
Arch: ejectStrings(raw, "arch"), | ||
Depends: ejectStrings(raw, "depend"), | ||
OptDepends: ejectStrings(raw, "optdepend"), | ||
MakeDepends: ejectStrings(raw, "makedepend"), | ||
CheckDepends: ejectStrings(raw, "checkdepend"), | ||
Backup: ejectStrings(raw, "backup"), | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
}, nil | ||
} | ||
|
||
func ejectString(raw, field string) string { | ||
splitted := strings.Split(raw, "\n"+field+" = ") | ||
if len(splitted) < 2 { | ||
return `` | ||
} | ||
return strings.Split(splitted[1], "\n")[0] | ||
} | ||
|
||
func ejectStrings(raw, field string) []string { | ||
splitted := strings.Split(raw, "\n"+field+" = ") | ||
if len(splitted) < 2 { | ||
return nil | ||
} | ||
var rez []string | ||
for i, v := range splitted { | ||
if i == 0 { | ||
continue | ||
} | ||
rez = append(rez, strings.Split(v, "\n")[0]) | ||
} | ||
return rez | ||
} | ||
|
||
func ejectInt64(raw, field string) int64 { | ||
splitted := strings.Split(raw, "\n"+field+" = ") | ||
if len(splitted) < 2 { | ||
return 0 | ||
} | ||
i, err := strconv.ParseInt(strings.Split(splitted[1], "\n")[0], 10, 64) | ||
if err != nil { | ||
return 0 | ||
} | ||
return i | ||
} | ||
|
||
func ByteCountSI(b int64) string { | ||
const unit = 1000 | ||
if b < unit { | ||
return fmt.Sprintf("%d B", b) | ||
} | ||
div, exp := int64(unit), 0 | ||
for n := b / unit; n >= unit; n /= unit { | ||
div *= unit | ||
exp++ | ||
} | ||
return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "kMGTPE"[exp]) | ||
} | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
|
||
func ReadableTime(unix int64) string { | ||
return time.Unix(unix, 0).Format(time.DateTime) | ||
} | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
|
||
func md5sum(data []byte) string { | ||
sum := md5.Sum(data) | ||
return hex.EncodeToString(sum[:]) | ||
} | ||
|
||
func sha256sum(data []byte) string { | ||
sum := sha256.Sum256(data) | ||
return hex.EncodeToString(sum[:]) | ||
} | ||
|
||
// This function returns pacman package description in unarchived raw database | ||
// format. | ||
func (m *Metadata) GetDbDesc() string { | ||
return strings.Join(rmEmptyStrings([]string{ | ||
formatField("FILENAME", m.Filename), | ||
formatField("NAME", m.Name), | ||
formatField("BASE", m.Base), | ||
formatField("VERSION", m.Version), | ||
formatField("DESC", m.Description), | ||
formatField("CSIZE", m.CompressedSize), | ||
formatField("ISIZE", m.InstalledSize), | ||
formatField("MD5SUM", m.MD5), | ||
formatField("SHA256SUM", m.SHA256), | ||
formatField("URL", m.URL), | ||
formatField("LICENSE", m.License), | ||
formatField("ARCH", m.Arch), | ||
formatField("BUILDDATE", m.BuildDate), | ||
formatField("PACKAGER", m.Packager), | ||
formatField("PROVIDES", m.Provides), | ||
formatField("DEPENDS", m.Depends), | ||
formatField("OPTDEPENDS", m.OptDepends), | ||
formatField("MAKEDEPENDS", m.MakeDepends), | ||
formatField("CHECKDEPENDS", m.CheckDepends), | ||
}), "\n\n") + "\n\n" | ||
} | ||
|
||
func formatField(field string, value any) string { | ||
switch value := value.(type) { | ||
case []string: | ||
if value == nil { | ||
return `` | ||
} | ||
val := strings.Join(value, "\n") | ||
return fmt.Sprintf("%%%s%%\n%s", field, val) | ||
case string: | ||
return fmt.Sprintf("%%%s%%\n%s", field, value) | ||
case int64: | ||
return fmt.Sprintf("%%%s%%\n%d", field, value) | ||
} | ||
return `` | ||
} | ||
|
||
func rmEmptyStrings(s []string) []string { | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
var r []string | ||
for _, str := range s { | ||
if str != "" { | ||
r = append(r, str) | ||
} | ||
} | ||
return r | ||
} | ||
|
||
// Function takes path to directory with pacman database and updates package | ||
// it with current metadata. | ||
func (m *Metadata) PutToDb(dir string, mode fs.FileMode) error { | ||
descdir := path.Join(dir, m.Name+"-"+m.Version) | ||
err := os.MkdirAll(descdir, mode) | ||
if err != nil { | ||
return err | ||
} | ||
return os.WriteFile(path.Join(descdir, "desc"), []byte(m.GetDbDesc()), mode) | ||
} | ||
|
||
// Function takes raw database archive bytes and destination directory as | ||
// arguements and unpacks database contents to destination directory. | ||
func UnpackDb(src, dst string) error { | ||
return archiver.DefaultTarGz.Unarchive(src, dst) | ||
} | ||
|
||
// Function takes path to source directory with raw pacman description files | ||
// for pacman database, creates db.tar.gz archive and related symlink for | ||
// provided path. | ||
func PackDb(src, dst string) error { | ||
if !strings.HasSuffix(dst, ".db.tar.gz") { | ||
return fmt.Errorf("dst should end with '.db.tar.gz': %s", dst) | ||
} | ||
symlink := strings.TrimSuffix(dst, ".tar.gz") | ||
if _, err := os.Stat(dst); err == nil { | ||
err = os.RemoveAll(dst) | ||
if err != nil { | ||
return err | ||
} | ||
err = os.RemoveAll(symlink) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
des, err := os.ReadDir(src) | ||
if err != nil { | ||
return err | ||
} | ||
var pkgdescs []string | ||
for _, de := range des { | ||
pkgdescs = append(pkgdescs, path.Join(src, de.Name())) | ||
} | ||
err = archiver.DefaultTarGz.Archive(pkgdescs, dst) | ||
if err != nil { | ||
return err | ||
} | ||
return os.Symlink(dst, symlink) | ||
} | ||
|
||
// Join database or package names to prevent collisions with same packages in | ||
// different user spaces. Skips empty strings and returns name joined with | ||
// dots. | ||
func Join(s ...string) string { | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
rez := "" | ||
for i, v := range s { | ||
if v == "" { | ||
continue | ||
} | ||
if i+1 == len(s) { | ||
rez += v | ||
continue | ||
} | ||
rez += v + "." | ||
} | ||
return rez | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.