You've already forked linuxdeploy
mirror of
https://github.com/encounter/linuxdeploy.git
synced 2026-03-30 11:18:58 -07:00
@@ -11,17 +11,36 @@ namespace linuxdeploy {
|
||||
using namespace log;
|
||||
|
||||
std::shared_ptr<ICopyrightFilesManager> ICopyrightFilesManager::getInstance() {
|
||||
auto check_command = [](const std::string& command) {
|
||||
auto p = subprocess::Popen(
|
||||
command,
|
||||
subprocess::output(subprocess::PIPE),
|
||||
subprocess::error(subprocess::PIPE)
|
||||
);
|
||||
// very simple but for our purposes good enough which like algorithm to find binaries in $PATH
|
||||
// TODO: move into separate function to be used in the entire code base
|
||||
// FIXME: remove dependency on subprocess library
|
||||
static const auto which = [](const std::string& name) -> bf::path {
|
||||
const auto* path = getenv("PATH");
|
||||
|
||||
return p.wait();
|
||||
if (path == nullptr)
|
||||
return "";
|
||||
|
||||
for (const auto& binDir : subprocess::util::split(path, ":")) {
|
||||
if (!bf::is_directory(binDir)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (bf::directory_iterator it(binDir); it != bf::directory_iterator{}; ++it) {
|
||||
const auto binary = it->path();
|
||||
|
||||
std::cout << binary << std::endl;
|
||||
|
||||
if (binary.filename() == name) {
|
||||
// TODO: check if file is executable (skip otherwise)
|
||||
return binary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
if (check_command("command -v dpkg-query") == 0) {
|
||||
if (!which("dpkg-query").empty()) {
|
||||
ldLog() << LD_DEBUG << "Using dpkg-query to search for copyright files" << std::endl;
|
||||
return std::make_shared<DpkgQueryCopyrightFilesManager>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user