Started stress testing script [CI SKIP]

This commit is contained in:
Jef Roosens 2022-01-30 14:13:37 +01:00
parent ae579f83b5
commit 4c56351132
Signed by untrusted user: Jef Roosens
GPG key ID: B580B976584B5F30
5 changed files with 136 additions and 7 deletions

View file

@ -12,6 +12,9 @@ fn C.archive_read_new() &C.archive
// Configure the archive to work with zstd compression
fn C.archive_read_support_filter_zstd(&C.archive)
// Configure the archive to work with gzip compression
fn C.archive_read_support_filter_gzip(&C.archive)
// Configure the archive to work with a tarball content
fn C.archive_read_support_format_tar(&C.archive)

View file

@ -111,19 +111,21 @@ pub fn read_pkg(pkg_path string) ?Pkg {
// Sinds 2020, all newly built Arch packages use zstd
C.archive_read_support_filter_zstd(a)
C.archive_read_support_filter_gzip(a)
// The content should always be a tarball
C.archive_read_support_format_tar(a)
// TODO find out where does this 10240 come from
r = C.archive_read_open_filename(a, &char(pkg_path.str), 10240)
defer {
C.archive_read_free(a)
}
if r != C.ARCHIVE_OK {
return error('Failed to open package.')
}
defer {
C.archive_read_free(a)
}
mut buf := voidptr(0)
mut files := []string{}
mut pkg_info := PkgInfo{}
@ -150,10 +152,8 @@ pub fn read_pkg(pkg_path string) ?Pkg {
}
C.archive_read_data(a, buf, size)
unsafe {
println(cstring_to_vstring(buf))
}
pkg_info = parse_pkg_info_string(unsafe { cstring_to_vstring(buf) }) ?
pkg_text := unsafe { cstring_to_vstring(buf) }
pkg_info = parse_pkg_info_string(pkg_text) ?
} else {
C.archive_read_data_skip(a)
}

View file

@ -96,6 +96,7 @@ fn (r &Repo) pkg_path(pkg &package.Pkg) string {
// Re-generate the repo archive files
fn (r &Repo) sync() ? {
// TODO also write files archive
lock r.mutex {
a := C.archive_write_new()
entry := C.archive_entry_new()
@ -106,6 +107,7 @@ fn (r &Repo) sync() ? {
C.archive_write_add_filter_gzip(a)
C.archive_write_set_format_pax_restricted(a)
// TODO add symlink to .tar.gz version
repo_path := os.join_path_single(r.repo_dir, 'repo.db')
C.archive_write_open_filename(a, &char(repo_path.str))

View file

@ -76,9 +76,17 @@ fn (mut app App) put_package() web.Result {
added := app.repo.add_from_path(pkg_path) or {
app.lerror('Error while adding package: $err.msg')
os.rm(pkg_path) or {
app.lerror("Failed to remove download '$pkg_path'.")
}
return app.text('Failed to add package.')
}
if !added {
os.rm(pkg_path) or {
app.lerror("Failed to remove download '$pkg_path'.")
}
app.lwarn('Duplicate package.')
return app.text('File already exists.')