#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 {
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;
}