Merge branch 'dev' into multi-arch-repos [CI SKIP]

This commit is contained in:
Jef Roosens 2022-02-20 09:31:12 +01:00
commit c3335fdb84
Signed by: Jef Roosens
GPG key ID: 955C0660072F691F
12 changed files with 44 additions and 112 deletions

View file

@ -65,6 +65,9 @@ fn (r &Repo) add(pkg &package.Pkg) ?bool {
return false
}
// We remove the older package version first, if present
r.remove(pkg.info.name, false) ?
os.mkdir(pkg_dir) or { return error('Failed to create package directory.') }
os.write_file(os.join_path_single(pkg_dir, 'desc'), pkg.to_desc()) or {
@ -83,6 +86,31 @@ fn (r &Repo) add(pkg &package.Pkg) ?bool {
return true
}
// remove removes a package from the database. It returns false if the package
// wasn't present in the database.
fn (r &Repo) remove(pkg_name string, sync bool) ?bool {
// We iterate over every directory in the repo dir
for d in os.ls(r.repo_dir) ? {
name := d.split('-')#[..-2].join('-')
if name == pkg_name {
// We lock the mutex here to prevent other routines from creating a
// new archive while we removed an entry
lock r.mutex {
os.rmdir_all(os.join_path_single(r.repo_dir, d)) ?
}
if sync {
r.sync() ?
}
return true
}
}
return false
}
// Returns the path where the given package's desc & files files are stored
fn (r &Repo) pkg_path(pkg &package.Pkg) string {
return os.join_path(r.repo_dir, '$pkg.info.name-$pkg.info.version')

View file

@ -34,7 +34,7 @@ fn parse_attrs(name string, attrs []string) ?([]http.Method, string) {
}
if x.len > 0 {
return IError(http.UnexpectedExtraAttributeError{
msg: 'Encountered unexpected extra attributes: $x'
attributes: x
})
}
if methods.len == 0 {
@ -49,8 +49,8 @@ fn parse_attrs(name string, attrs []string) ?([]http.Method, string) {
fn parse_query_from_url(url urllib.URL) map[string]string {
mut query := map[string]string{}
for k, v in url.query().data {
query[k] = v.data[0]
for v in url.query().data {
query[v.key] = v.value
}
return query
}

View file

@ -22,7 +22,7 @@ pub struct Result {}
pub const (
methods_with_form = [http.Method.post, .put, .patch]
headers_close = http.new_custom_header_from_map({
'Server': 'VWeb'
'Server': 'VWeb'
http.CommonHeader.connection.str(): 'close'
}) or { panic('should never fail') }