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"
12 #include "common/installer_context.h"
13 #include "common/shared_dirs.h"
14 #include "common/utils/file_util.h"
15 #include "common/utils/user_util.h"
17 namespace fs = std::filesystem;
18 namespace ci = common_installer;
22 const char kDataDir[] = "data";
23 const char kCacheDir[] = "cache";
24 const char kSharedDir[] = ".shared";
25 const char kSubssesionDir[] = "subsession";
27 bool RemoveContents(const fs::path& path) {
28 if (!fs::exists(path))
31 for (fs::directory_iterator iter(path); iter != fs::directory_iterator();
33 if (!ci::RemoveAll(iter->path()))
42 namespace common_installer {
43 namespace filesystem {
45 Step::Status StepRemoveUserData::process() {
46 // Currently this step is only for ReadonlyUpdateUninstall mode.
47 if (context_->keep_rwdata.get())
48 return Step::Status::OK;
50 UserList list = ci::GetUserList();
51 for (const auto& l : list) {
52 uid_t uid = std::get<0>(l);
53 fs::path owner_apps_rw(std::get<2>(l) / "apps_rw");
54 std::vector<fs::path> apps_rw_paths;
55 apps_rw_paths.push_back(std::move(owner_apps_rw));
56 for (auto& lw_user : GetLightUserList(uid))
57 apps_rw_paths.push_back(std::get<2>(l) / kSubssesionDir / lw_user /
60 for (auto& apps_rw : apps_rw_paths) {
61 if (!RemoveContents(apps_rw / context_->pkgid.get() / kDataDir)) {
62 LOG(ERROR) << "Failed to remove contents of data dir";
63 return Step::Status::APP_DIR_ERROR;
65 if (!RemoveContents(apps_rw / context_->pkgid.get() / kCacheDir)) {
66 LOG(ERROR) << "Failed to remove contents of cache dir";
67 return Step::Status::APP_DIR_ERROR;
69 if (!RemoveContents(apps_rw / kSharedDir / context_->pkgid.get() /
71 LOG(ERROR) << "Failed to remove contents of shared/data dir";
72 return Step::Status::APP_DIR_ERROR;
77 return Step::Status::OK;
80 } // namespace filesystem
81 } // namespace common_installer