Set group of cache dir as system_share 01/108401/2
authorSangyoon Jang <s89.jang@samsung.com>
Wed, 4 Jan 2017 08:00:16 +0000 (17:00 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Wed, 4 Jan 2017 10:09:46 +0000 (19:09 +0900)
cache dir should be treated as data, shared/data.

Change-Id: I9864c0f42ff4901e206d7051605e677d82284359
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/common/shared_dirs.cc
src/common/step/filesystem/step_change_ownership_and_permission.cc

index e49de388717f316355c080cc431b23a1741815ff..c9d1de2d75a73e90cd4e850af4e256696683e41c 100644 (file)
@@ -119,7 +119,7 @@ bool SetDirectoryOwnerAndPermissions(const bf::path& subpath, uid_t uid,
   bool result = true;
   if (bf::is_directory(subpath)) {
     perms |= bf::owner_exe | bf::group_exe | bf::others_read | bf::others_exe;
-    if (subpath.filename() == "data") {
+    if (subpath.filename() == "data" || subpath.filename() == "cache") {
       perms |= bf::group_write | bf::set_gid_on_exe;
       boost::optional<gid_t> system_share =
           ci::GetGidByGroupName(kSystemShareGroupName);
index a6eb19eb5dff51c95fd1ff3e85e301f46a8d5683..466c64633ed0820de04fcf7a5ddb0de129917c6b 100644 (file)
@@ -30,8 +30,11 @@ namespace ci = common_installer;
 namespace {
 
 const char kSystemShareGroupName[] = "system_share";
-const char kDataDir[] = "data";
-const char kSharedDataDir[] = "shared/data";
+const std::vector<const char*> kDataDirEntries = {
+  {"data"},
+  {"shared/data"},
+  {"cache"},
+};
 
 bool GrantPermission755(const bf::path& path) {
   auto permission = bf::perms::owner_all |
@@ -66,29 +69,20 @@ bool ChangeDataDir(const bf::path& pkg_path, uid_t uid) {
   }
 
   bf::perms prms = bf::add_perms | bf::group_write | bf::set_gid_on_exe;
-  bf::path data = pkg_path / kDataDir;
-  if (!ci::SetOwnership(data, uid, *gid)) {
-    LOG(ERROR) << "Failed to change owner: " << data
-               << "(" << uid << ", " << *gid << ")";
-    return false;
-  }
-  if (!ci::SetDirPermissions(data, prms)) {
-    LOG(ERROR) << "Failed to change permission: " << data
-               << std::oct << prms;
-    return false;
-  }
-  bf::path shareddata = pkg_path / kSharedDataDir;
-  if (!bf::exists(shareddata))
-    return true;
-  if (!ci::SetOwnership(shareddata, uid, *gid)) {
-    LOG(ERROR) << "Failed to change owner: " << shareddata
-               << "(" << uid << ", " << *gid << ")";
-    return false;
-  }
-  if (!ci::SetDirPermissions(shareddata, prms)) {
-    LOG(ERROR) << "Failed to change permission: " << shareddata
-               << std::oct << prms;
-    return false;
+  for (auto& entry : kDataDirEntries) {
+    bf::path path = pkg_path / entry;
+    if (!bf::exists(path))
+      continue;
+    if (!ci::SetOwnership(path, uid, *gid)) {
+      LOG(ERROR) << "Failed to change owner: " << path
+                 << "(" << uid << ", " << *gid << ")";
+      return false;
+    }
+    if (!ci::SetDirPermissions(path, prms)) {
+      LOG(ERROR) << "Failed to change permission: " << path
+                 << std::oct << prms;
+      return false;
+    }
   }
 
   return true;