From 33e695bdf30a2e1fd77a6c1226d01cf7a81e71f5 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 31 Jan 2022 22:59:12 +0100 Subject: [PATCH] Filenames now use the correct compression scheme (closes #56) --- src/archive.v | 3 +++ src/package.v | 22 ++++++++++++++++++---- test.py | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/archive.v b/src/archive.v index 3eaad5c3..8d1314fd 100644 --- a/src/archive.v +++ b/src/archive.v @@ -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 {} diff --git a/src/package.v b/src/package.v index b9bcae86..03103c98 100644 --- a/src/package.v +++ b/src/package.v @@ -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 diff --git a/test.py b/test.py index 17445b79..2d1e4f56 100644 --- a/test.py +++ b/test.py @@ -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))