Validate gadget resource paths
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 19 Feb 2024 23:44:55 +0000 (08:44 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 20 Feb 2024 00:19:54 +0000 (09:19 +0900)
The gadget resource path will be changed to
"/<package root path>/res/allowed/<res-type>".
Before mounting the gadget paths, the launchpad checks whether the path exists
or not. If it does not exist, the gadget path will be modified to remove
the "<res-type>".

Change-Id: Ib7d28fb0df986e56269351c5a2f94446b82ab0f2
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/launchpad-glib/util.cc

index b5861f61b708fa2e7d0aa81a81b5e4d6e8c6dc69..44cea5d8acb08da8849e5526ff3b59b88990adf3 100644 (file)
@@ -362,6 +362,19 @@ class AmdPacket : public tizen_base::Parcelable {
   int opt_ = 0;
 };
 
+std::vector<std::string> ValidateAndModifyGadgetPaths(
+    const std::vector<std::string> gadget_paths) {
+  std::vector<std::string> paths;
+  for (const auto& path : gadget_paths) {
+    if (access(path.c_str(), F_OK) == 0)
+      paths.push_back(path);
+    else
+      paths.push_back(fs::path(path).parent_path().string());
+  }
+
+  return paths;
+}
+
 }  // namespace
 
 void Util::SetEnvironments(const AppInfo* app_info) {
@@ -487,6 +500,7 @@ int Util::MountResourceDirectories(const AppInfo* app_info) {
 int Util::MountGadgetDirectories(const tizen_base::Bundle& b) {
   auto gadget_paths = b.GetStringArray(kAulMountGadgetPaths);
   if (!gadget_paths.empty()) {
+    gadget_paths = ValidateAndModifyGadgetPaths(gadget_paths);
     auto root_path = b.GetString(kAulRootPath);
     return MountDirectories(gadget_paths, root_path + "/bin");
   }