Revert "Don't create skel dirs for packages" 76/67676/13
authorSangyoon Jang <s89.jang@samsung.com>
Mon, 16 May 2016 10:41:33 +0000 (19:41 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Fri, 20 May 2016 06:46:05 +0000 (15:46 +0900)
This reverts commit cc661b012078be469db6b60cd2e8926d770c7a52.

The way of making per user directory will be changed.
Installer will create skel directories when install global app, and
the pkgdir-tool will copy those skel directories to each users home.

Change-Id: Ifd538689825cb019558222ecef1cd532b0c22922

src/common/shared_dirs.cc
src/common/shared_dirs.h
src/pkgdir_tool/pkgdir_tool.cc

index 72e9405..4e78a60 100644 (file)
@@ -53,6 +53,7 @@ const std::vector<const char*> kEntries = {
 };
 
 const char kTrustedDir[] = "shared/trusted";
+const char kSkelAppDir[] = "/etc/skel/apps_rw";
 const char kPackagePattern[] = R"(^[0-9a-zA-Z_-]+(\.?[0-9a-zA-Z_-]+)*$)";
 const char kExternalStorageDirPrefix[] = "SDCardA1/apps";
 
@@ -280,6 +281,45 @@ bool CreateUserDirectories(uid_t user, const std::string& pkgid,
   return true;
 }
 
+bool CreateSkelDirectories(const std::string& pkgid) {
+  bf::path path = bf::path(kSkelAppDir) / pkgid;
+  LOG(DEBUG) << "Creating directories in: " << path;
+  bs::error_code error;
+  bf::create_directories(path, error);
+
+  if (error) {
+    LOG(ERROR) << "Failed to create directory: " << path;
+    return false;
+  }
+
+  // TODO(jungh.yeon) : this is hotfix.
+  for (auto& entry : kEntries) {
+    bf::path subpath = path / entry;
+    bf::create_directories(subpath, error);
+    std::string label = "User::Pkg::" + pkgid;
+    if (error && !bf::exists(subpath)) {
+      LOG(ERROR) << "Failed to create directory: " << subpath;
+      return false;
+    }
+
+    int r =
+        lsetxattr(subpath.c_str(), "security.SMACK64TRANSMUTE", "TRUE", 4, 0);
+    if (r < 0) {
+      LOG(ERROR) << "Failed to apply transmute";
+      return false;
+    }
+
+    r = lsetxattr(subpath.c_str(), "security.SMACK64",
+                  label.c_str(), label.length(), 0);
+    if (r < 0) {
+      LOG(ERROR) << "Failed to apply label";
+      return false;
+    }
+  }
+
+  return true;
+}
+
 bool DeleteDirectories(const bf::path& app_dir, const std::string& pkgid) {
   bf::path base_dir = app_dir / pkgid;
   bs::error_code error;
@@ -337,10 +377,26 @@ bool DeletePerUserDirectories(const std::string& pkgid) {
   return true;
 }
 
+bool DeleteSkelDirectories(const std::string& pkgid) {
+  bf::path path = bf::path(kSkelAppDir) / pkgid;
+  LOG(DEBUG) << "Deleting directories in: " << path;
+  bs::error_code error;
+  bf::remove_all(path, error);
+  if (error) {
+    LOG(ERROR) << "Failed to delete directory: " << path;
+    return false;
+  }
+  return true;
+}
+
 }  // namespace
 
 namespace common_installer {
 
+bool CreateSkeletonDirectoriesForPackage(const std::string& pkgid) {
+  return CreateSkelDirectories(pkgid);
+}
+
 std::string GetDirectoryPathForInternalStorage() {
   const char* internal_storage_prefix = tzplatform_getenv(TZ_SYS_HOME);
   if (internal_storage_prefix)
@@ -508,6 +564,8 @@ bool SetPackageDirectorySmackRulesForAllUsers(const std::string& pkg_path,
 bool PerformDirectoryDeletionForAllUsers(const std::string& pkgid) {
   if (!DeletePerUserDirectories(pkgid))
     return false;
+  if (!DeleteSkelDirectories(pkgid))
+    return false;
   return true;
 }
 
index 4436024..7904c1f 100644 (file)
@@ -30,6 +30,7 @@ using PkgList = std::vector<PkgInfo>;
  *
  * \param pkgid id of package
  * \param author_id id of author
+ * \param create_skel_directories flag
  *
  * \return true if succeed, false otherwise
  *
@@ -43,6 +44,7 @@ bool PerformInternalDirectoryCreationForUser(uid_t uid,
  *
  * \param pkgid id of package
  * \param author_id id of author
+ * \param create_skel_directories flag
  *
  * \return true if succeed, false otherwise
  *
@@ -56,6 +58,7 @@ bool PerformExternalDirectoryCreationForUser(uid_t uid,
  *
  * \param pkgid id of package
  * \param author_id id of author
+ * \param create_skel_directories flag
  *
  * \return true if succeed, false otherwise
  *
@@ -68,6 +71,7 @@ bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
  *
  * \param pkgid id of package
  * \param author_id id of author
+ * \param create_skel_directories flag
  *
  * \return true if succeed, false otherwise
  *
@@ -149,6 +153,14 @@ std::string GetDirectoryPathForInternalStorage();
  */
 std::string GetDirectoryPathForExternalStorage();
 
+/**
+ * \brief Create skeleton directories for package
+ *
+ * \return bool true if succeed, false otherwise
+ *
+ */
+bool CreateSkeletonDirectoriesForPackage(const std::string& pkgid);
+
 }  // namespace common_installer
 
 #endif  // COMMON_SHARED_DIRS_H_
index 56dc056..55aed4a 100644 (file)
@@ -146,6 +146,8 @@ int main(int argc, char** argv) {
                                                      p.pkg_id,
                                                      p.author_id,
                                                      p.api_version);
+
+        ci::CreateSkeletonDirectoriesForPackage(p.pkg_id);
       }
       break;
       case DirectoryOperation::DELETE: {