MatN work for versatile appimage creation for all types of os
[goodguy/cinelerra.git] / cinelerra-5.1 / tools / makeappimagetool / copyright_dpkgquery.cpp
diff --git a/cinelerra-5.1/tools/makeappimagetool/copyright_dpkgquery.cpp b/cinelerra-5.1/tools/makeappimagetool/copyright_dpkgquery.cpp
new file mode 100644 (file)
index 0000000..6c4f3f0
--- /dev/null
@@ -0,0 +1,38 @@
+// local includes
+#include "includes/copyright_dpkgquery.h"
+#include "includes/log.h"
+#include "includes/util.h"
+#include "includes/subprocess.h"
+
+namespace linuxdeploy {
+    namespace core {
+        namespace copyright {
+            using namespace log;
+
+            std::vector<bf::path> DpkgQueryCopyrightFilesManager::getCopyrightFilesForPath(const bf::path& path) {
+                subprocess::subprocess proc{{"dpkg-query", "-S", path.c_str()}};
+
+                auto result = proc.run();
+
+                if (result.exit_code() != 0 || result.stdout_contents().empty()) {
+                    ldLog() << LD_WARNING << "Could not find copyright files for file" << path << "using dpkg-query" << std::endl;
+                    return {};
+                }
+
+                auto packageName = util::split(util::splitLines(result.stdout_string())[0], ':')[0];
+
+                if (!packageName.empty()) {
+                    auto copyrightFilePath = bf::path("/usr/share/doc") / packageName / "copyright";
+
+                    if (bf::is_regular_file(copyrightFilePath)) {
+                        return {copyrightFilePath};
+                    }
+                } else {
+                    ldLog() << LD_WARNING << "Could not find copyright files for file" << path << "using dpkg-query" << std::endl;
+                }
+
+                return {};
+            }
+        }
+    }
+}