Skip to content

Commit

Permalink
🚧 conf-window: fix regression with custom PKGEXT
Browse files Browse the repository at this point in the history
fixes #21
  • Loading branch information
vnepogodin committed Sep 7, 2024
1 parent 8cf0331 commit 2f5414b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/conf-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,27 @@ auto get_source_array_from_pkgbuild(std::string_view kernel_name_path, std::stri
return utils::make_multiline(src_entries, ' ');
}

auto get_pkgext_value_from_makepkgconf() noexcept -> std::string {
using namespace std::string_view_literals;
using namespace std::string_literals;
static constexpr auto testscript_src = "#!/usr/bin/bash\nsource \"/etc/makepkg.conf\"\necho \"${PKGEXT}\""sv;

const auto& testscript_path = fmt::format(FMT_COMPILE("{}/.testscriptpkgext"), fs::current_path().string());
if (utils::write_to_file(testscript_path, testscript_src)) {
fs::permissions(testscript_path,
fs::perms::owner_exec | fs::perms::group_exec | fs::perms::others_exec,
fs::perm_options::add);
}

auto pkgext_val = utils::exec(testscript_path);
if (pkgext_val.empty()) {
fmt::print(stderr, "failed to get PKGEXT from /etc/makepkg.conf");
return ".pkg.tar.zst"s;
}
return pkgext_val;
}


auto prepare_func_names(std::vector<std::string> parse_lines, std::string_view pkgver_str) noexcept -> std::vector<std::string> {
using namespace std::string_view_literals;

Expand All @@ -200,6 +221,9 @@ auto prepare_func_names(std::vector<std::string> parse_lines, std::string_view p
return rng_str.starts_with("package_"sv);
};

// fetch the pkgext from /etc/makepkg.conf, and fallback to '.pkg.tar.zst' which is default value of makepkg
const auto& pkgext_val = get_pkgext_value_from_makepkgconf();

std::vector<std::string> pkg_globs{};
pkg_globs = parse_lines
| std::ranges::views::transform([&](auto&& rng) {
Expand All @@ -219,7 +243,7 @@ auto prepare_func_names(std::vector<std::string> parse_lines, std::string_view p
if (line.starts_with(needle_prefix)) {
line.remove_prefix(needle_prefix.size());
}
return fmt::format(FMT_COMPILE("{}-{}-*.pkg.tar.zst"), line, pkgver_str);
return fmt::format(FMT_COMPILE("{}-{}-*{}"), line, pkgver_str, pkgext_val);
})
| std::ranges::to<std::vector<std::string>>();
return pkg_globs;
Expand Down

0 comments on commit 2f5414b

Please sign in to comment.