Filenames now use the correct compression scheme (closes #56)

pull/60/head
Jef Roosens 2022-01-31 22:59:12 +01:00
parent 8a0beffbe2
commit 33e695bdf3
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
3 changed files with 22 additions and 5 deletions

View File

@ -63,6 +63,9 @@ fn C.archive_write_close(&C.archive)
// Free the write archive
fn C.archive_write_free(&C.archive)
// Returns the name of the filter
fn C.archive_filter_code(&C.archive, int) int
#include "archive_entry.h"
struct C.archive_entry {}

View File

@ -6,9 +6,10 @@ import util
// Represents a read archive
struct Pkg {
pub:
path string [required]
info PkgInfo [required]
files []string [required]
path string [required]
info PkgInfo [required]
files []string [required]
compression int [required]
}
// Represents the contents of a .PKGINFO file
@ -125,6 +126,11 @@ pub fn read_pkg(pkg_path string) ?Pkg {
C.archive_read_free(a)
}
// 0: no compression (just a tarball)
// 1: gzip
// 14: zstd
compression_code := C.archive_filter_code(a, 0)
mut files := []string{}
mut pkg_info := PkgInfo{}
@ -164,6 +170,7 @@ pub fn read_pkg(pkg_path string) ?Pkg {
path: pkg_path
info: pkg_info
files: files
compression: compression_code
}
}
@ -175,7 +182,14 @@ fn format_entry(key string, value string) string {
pub fn (pkg &Pkg) filename() string {
p := pkg.info
return '$p.name-$p.version-${p.arch}.pkg.tar.zst'
ext := match pkg.compression {
0 { '.tar' }
1 { '.tar.gz' }
14 { '.tar.zst' }
else { panic("Another compression code shouldn't be possible. Faulty code: $pkg.compression") }
}
return '$p.name-$p.version-${p.arch}.pkg$ext'
}
// to_desc returns a desc file valid string representation

View File

@ -67,7 +67,7 @@ def create_random_package(tmpdir, words, pkg_name_min_len, pkg_name_max_len, min
return tar_info
with tarfile.open(tar_path, "w") as tar:
with tarfile.open(tar_path, "w:gz") as tar:
# Add random .PKGINFO file
pkginfo_file = sub_path / ".PKGINFO"
pkginfo_file.write_text(create_random_pkginfo(words, pkg_name_min_len, pkg_name_max_len))