Implement RpkAppQueryInterface
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 13 May 2021 01:57:06 +0000 (10:57 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Fri, 14 May 2021 00:45:24 +0000 (09:45 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/rpk/rpk_app_query_interface.cc

index e9220f3..e6eeb3e 100644 (file)
@@ -3,18 +3,53 @@
 // found in the LICENSE file.
 
 #include "rpk/rpk_app_query_interface.h"
+#include "rpk_manifest_handlers/rpk_config_parser.h"
+#include "rpk_manifest_handlers/package_handler.h"
 
 #include <string>
 
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace {
+
+const char kManifestFileName[] = "tizen-manifest.xml";
+
+const char kManifestKey[] = "manifest";
+
+}  // namespace
+
 namespace rpk {
 
 std::string RpkAppQueryInterface::GetManifestFileName() const {
-  return {};
+  return std::string(kManifestFileName);
 }
 
 std::string RpkAppQueryInterface::GetPkgIdFromPath(
     const std::string& path) const {
-  return {};
+  bf::path tmp_path = ExtractManifest(path);
+  if (tmp_path.empty())
+    return {};
+  bf::path manifest_path = tmp_path / kManifestFileName;
+  if (!bf::exists(manifest_path)) {
+    ClearTemporaryFile(tmp_path);
+    return {};
+  }
+
+  rpk::parse::RPKConfigParser parser;
+  if (!parser.ParseManifest(manifest_path)) {
+    ClearTemporaryFile(tmp_path);
+    return {};
+  }
+  auto package_info = std::static_pointer_cast<const rpk::parse::PackageInfo>(
+      parser.GetManifestData(kManifestKey));
+  if (!package_info) {
+    ClearTemporaryFile(tmp_path);
+    return {};
+  }
+  std::string pkg_id = package_info->package();
+  ClearTemporaryFile(tmp_path);
+  return pkg_id;
 }
 
 }  // namespace rpk