Fix detection of copyright tools

CC #104
This commit is contained in:
TheAssassin
2019-11-18 23:13:44 +01:00
parent 9783db602e
commit 1bd5453c61
+27 -8
View File
@@ -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>();
}