Check if in uninstalled app dirs are mounted files 85/112185/8
authorBartlomiej Kunikowski <b.kunikowski@partner.samsung.com>
Thu, 26 Jan 2017 16:59:22 +0000 (17:59 +0100)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Fri, 10 Feb 2017 08:37:49 +0000 (00:37 -0800)
There is a problem when we want uninstall app in which
directory are mounted some file.

This patch perform checking if in deinstalled app
directories are some mounted files. If there are some
mounted files then deinstallation is not allowed.

There are more problems when in app directories
are some files that are not removable.

Change-Id: Ic986514c10228cc7beeb100b859a36a8df6cf830

src/common/step/pkgmgr/step_check_removable.cc

index 7dd0bc8..a127c15 100644 (file)
@@ -6,8 +6,25 @@
 
 #include <pkgmgr-info.h>
 
+#include <boost/filesystem/operations.hpp>
+
+#include <pkgmgr_query.h>
+#include <utils/user_util.h>
+
+#include <fstream>
+#include <string>
+#include <vector>
+
 #include "common/app_installer.h"
 
+namespace {
+
+const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+const gid_t kGlobalUserGid = tzplatform_getgid(TZ_SYS_GLOBALAPP_USER);
+const bf::path kMountsPath = "/proc/mounts";
+
+}
+
 namespace common_installer {
 namespace pkgmgr {
 
@@ -45,6 +62,54 @@ Step::Status StepCheckRemovable::process() {
 Step::Status StepCheckRemovable::precheck() {
   if (context_->pkgid.get().empty())
     return Status::INVALID_VALUE;
+
+  std::string pkgid = context_->pkgid.get();
+  std::ifstream mounts_file;
+  std::vector<std::string> lines;
+
+  mounts_file.open(kMountsPath.string());
+
+  if (!mounts_file.is_open()) {
+    LOG(ERROR) << "File " << kMountsPath << " no open";
+    return Status::ERROR;
+  }
+
+  std::string line;
+  while (mounts_file >> line) {
+    lines.push_back(line);
+  }
+
+  mounts_file.close();
+
+  if (lines.empty()) {
+    return Status::OK;
+  }
+
+  UserList list = GetUserList();
+  list.emplace_back(kGlobalUserUid, kGlobalUserGid,
+                    GetRootAppPath(false, kGlobalUserUid));
+  for (auto l : list) {
+    bf::path pkg_path;
+    if (std::get<0>(l) != kGlobalUserUid) {
+      pkg_path = std::get<2>(l) / "apps_rw" / pkgid;
+    } else {
+      pkg_path = std::get<2>(l) / pkgid;
+    }
+
+    if (!bf::exists(pkg_path))
+      continue;
+    LOG(DEBUG) << "Checking if directories of " << pkgid
+        << ", for uid: " << std::get<0>(l) << ", are removable";
+
+    for (auto d : lines) {
+      if (d.find(pkg_path.string()) != std::string::npos) {
+        LOG(ERROR) << "The directory: " << pkg_path << " contains a mounted " <<
+            "file! Please unmount it before you can uninstall this app!";
+        return Status::OPERATION_NOT_ALLOWED;
+      }
+    }
+  }
+
   return Status::OK;
 }