From da7e41e8cada9d61cd14b00bb9f7ffb7e520388e Mon Sep 17 00:00:00 2001 From: GreekStapler Date: Thu, 2 Feb 2023 11:42:00 +0000 Subject: [PATCH] refactor: Package extension now depends on what compression method was detected. --- src/package/vieter_package.c | 22 ++++++++++++++++++---- test/package/test_package.c | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/package/vieter_package.c b/src/package/vieter_package.c index e5530e4..5c61d45 100644 --- a/src/package/vieter_package.c +++ b/src/package/vieter_package.c @@ -185,11 +185,25 @@ char *vieter_package_to_description(vieter_package *pkg) { int i; // special case for FILENAME - // assuming .pkg.tar.zst; other formats are valid, this should account for - // that + char *ext; + switch (pkg->compression) { + case 0: + ext = ".tar"; + break; + case 1: + ext = ".tar.gz"; + break; + case 6: + ext = ".tar.xz"; + break; + case 14: + ext = ".tar.zst"; + break; + } + size_to_be_written = - snprintf(aux, small_buff_size, "%%FILENAME%%\n%s-%s-%s.pkg.tar.zst", - pkg_info->name, pkg_info->version, pkg_info->arch); + snprintf(aux, small_buff_size, "%%FILENAME%%\n%s-%s-%s.pkg%s", + pkg_info->name, pkg_info->version, pkg_info->arch, ext); // We neither want to let an arbritrarily long input to overflow the buffer // nor to truncate perfectly valid inputs diff --git a/test/package/test_package.c b/test/package/test_package.c index 3c8b249..d4dd981 100644 --- a/test/package/test_package.c +++ b/test/package/test_package.c @@ -78,6 +78,8 @@ void test_pkg_read_archive_desc() { fclose(f); TEST_CHECK(!strcmp(description, desc)); + + vieter_package_free(&pkg); } TEST_LIST = {