Fix access denied error at dotnet AOT plugin 27/314827/5
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 22 Jul 2024 00:23:29 +0000 (09:23 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 22 Jul 2024 00:42:48 +0000 (09:42 +0900)
Set ownership manually after copying new contents.

Change-Id: Ic2316f7be5f319309aa057617f90833b719e07a0
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/step/backup/step_copy_backup.cc

index 6460cf2bbe66b39d2414e8ed4cdce92fc3004057..b957d9d54d69f3568b4c27cf79aa8ccb818cead1 100644 (file)
@@ -36,7 +36,7 @@ bool CheckFreeSpace(const fs::path& backup_path, const fs::path& shared_path) {
   return true;
 }
 
-bool CreateSharedRes(const fs::path& src, const fs::path& dst) {
+bool CreateSharedRes(const fs::path& dst) {
   std::error_code error;
 
   fs::create_directories(dst / kSharedResPath, error);
@@ -45,11 +45,6 @@ bool CreateSharedRes(const fs::path& src, const fs::path& dst) {
     return false;
   }
 
-  if (!ci::CopyOwnershipAndPermissions(src / "shared", dst / "shared") ||
-      !ci::CopyOwnershipAndPermissions(src / kSharedResPath,
-          dst / kSharedResPath))
-    return false;
-
   return true;
 }
 
@@ -236,8 +231,14 @@ bool StepCopyBackup::NewContent() {
     return false;
   }
 
-  if (ShouldBackupSharedRes()) {
-    if (!CreateSharedRes(backup_path_, context_->GetPkgPath()))
+  // This is a trick that making installer copy new shared/res contents
+  // instead of move(move will fail by directory not empty error). Because
+  // transmute attribute of smack is not working on move operation.
+  // Early smack labeling is needed because of accessing shared/res from
+  // other applications during package update.
+  bool should_backup_shared_res = ShouldBackupSharedRes();
+  if (should_backup_shared_res) {
+    if (!CreateSharedRes(context_->GetPkgPath()))
       return false;
   }
 
@@ -262,6 +263,18 @@ bool StepCopyBackup::NewContent() {
     LOG(ERROR) << "Failed to set ownership";
     return false;
   }
+
+  // Set ownership of the contents of shared/res same as installer (originally
+  // it was set as tizenglobalapps by copy operation instead of move) to avoid
+  // access denied error at child process of installer (e.g. dotnet AOT plugin)
+  if (should_backup_shared_res) {
+    if (!ci::SetOwnershipAll(
+          install_path_ / "shared/res", getuid(), getgid())) {
+      LOG(ERROR) << "Failed to set ownership";
+      return false;
+    }
+  }
+
   LOG(INFO) << "Successfully move: " << context_->unpacked_dir_path.get()
             << " to: " << install_path_ << " directory";