2 #include "includes/copyright_dpkgquery.h"
3 #include "includes/log.h"
4 #include "includes/util.h"
5 #include "includes/subprocess.h"
7 namespace linuxdeploy {
12 std::vector<bf::path> DpkgQueryCopyrightFilesManager::getCopyrightFilesForPath(const bf::path& path) {
13 subprocess::subprocess proc{{"dpkg-query", "-S", path.c_str()}};
15 auto result = proc.run();
17 if (result.exit_code() != 0 || result.stdout_contents().empty()) {
18 ldLog() << LD_WARNING << "Could not find copyright files for file" << path << "using dpkg-query" << std::endl;
22 auto packageName = util::split(util::splitLines(result.stdout_string())[0], ':')[0];
24 if (!packageName.empty()) {
25 auto copyrightFilePath = bf::path("/usr/share/doc") / packageName / "copyright";
27 if (bf::is_regular_file(copyrightFilePath)) {
28 return {copyrightFilePath};
31 ldLog() << LD_WARNING << "Could not find copyright files for file" << path << "using dpkg-query" << std::endl;