Add parameter to StepRemovePerUserStorageDirectories
[platform/core/appfw/app-installers.git] / src / common / step / filesystem / step_remove_per_user_storage_directories.cc
1 // Copyright (c) 2016 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.
4
5 #include "common/step/filesystem/step_remove_per_user_storage_directories.h"
6
7 #include <memory>
8 #include <string>
9 #include <vector>
10
11 #include "common/step/step.h"
12 #include "common/step/filesystem/step_create_storage_directories.h"
13 #include "common/step/filesystem/step_create_globalapp_symlinks.h"
14 #include "common/installer_context.h"
15 #include "common/shared_dirs.h"
16 #include "common/utils/pkgmgr_query.h"
17
18 namespace common_installer {
19 namespace filesystem {
20
21 Step::Status StepRemovePerUserStorageDirectories::process() {
22   if (context_->request_mode.get() != RequestMode::GLOBAL)
23     return Step::Status::OK;
24
25   if (!common_installer::DeletePerUserStorageDirectories(context_->pkgid.get(),
26           context_->keep_rwdata.get()))
27     return Status::APP_DIR_ERROR;
28
29   return Step::Status::OK;
30 }
31
32 Step::Status StepRemovePerUserStorageDirectories::undo() {
33   std::string author_id =
34       QueryCertificateAuthorCertificate(
35           context_->pkgid.get(), context_->uid.get());
36   context_->certificate_info.get().author_id.set(author_id);
37   std::vector<std::unique_ptr<Step>> steps;
38   steps.emplace_back(new StepCreateStorageDirectories(
39       context_, additional_shared_dirs_));
40   steps.emplace_back(new StepCreateGlobalAppSymlinks(context_));
41
42   for (auto& it : steps) {
43     Step::Status result;
44     result = it->precheck();
45     if (result != Step::Status::OK) {
46       LOG(ERROR) << "Fail to execute precheck of " << it->name();
47       return result;
48     }
49
50     result = it->process();
51     if (result != Step::Status::OK) {
52       LOG(ERROR) << "Fail to execute process of " << it->name();
53       return result;
54     }
55   }
56   return Step::Status::OK;
57 }
58
59 }  // namespace filesystem
60 }  // namespace common_installer
61