1 // Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/filesystem/step_remove_user_data.h"
11 #include "common/installer_context.h"
12 #include "common/shared_dirs.h"
13 #include "common/utils/file_util.h"
14 #include "common/utils/user_util.h"
16 namespace bf = boost::filesystem;
17 namespace ci = common_installer;
21 const char kDataDir[] = "data";
22 const char kCacheDir[] = "cache";
23 const char kSharedDir[] = ".shared";
24 const char kSubssesionDir[] = "subsession";
26 bool RemoveContents(const bf::path& path) {
27 if (!bf::exists(path))
30 for (bf::directory_iterator iter(path); iter != bf::directory_iterator();
32 if (!ci::RemoveAll(iter->path()))
41 namespace common_installer {
42 namespace filesystem {
44 Step::Status StepRemoveUserData::process() {
45 // Currently this step is only for ReadonlyUpdateUninstall mode.
46 if (context_->keep_rwdata.get())
47 return Step::Status::OK;
49 UserList list = ci::GetUserList();
50 for (const auto& l : list) {
51 uid_t uid = std::get<0>(l);
52 bf::path owner_apps_rw(std::get<2>(l) / "apps_rw");
53 std::vector<bf::path> apps_rw_paths;
54 apps_rw_paths.push_back(std::move(owner_apps_rw));
55 for (auto& lw_user : GetLightUserList(uid))
56 apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
59 for (auto& apps_rw : apps_rw_paths) {
60 if (!RemoveContents(apps_rw / context_->pkgid.get() / kDataDir)) {
61 LOG(ERROR) << "Failed to remove contents of data dir";
62 return Step::Status::APP_DIR_ERROR;
64 if (!RemoveContents(apps_rw / context_->pkgid.get() / kCacheDir)) {
65 LOG(ERROR) << "Failed to remove contents of cache dir";
66 return Step::Status::APP_DIR_ERROR;
68 if (!RemoveContents(apps_rw / kSharedDir / context_->pkgid.get() /
70 LOG(ERROR) << "Failed to remove contents of shared/data dir";
71 return Step::Status::APP_DIR_ERROR;
76 return Step::Status::OK;
79 } // namespace filesystem
80 } // namespace common_installer