Add recovery mode for ReadonlyUpdateInstall
[platform/core/appfw/app-installers.git] / src / common / step / pkgmgr / step_recover_application.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "common/step/pkgmgr/step_recover_application.h"
6
7 #include <boost/filesystem.hpp>
8
9 #include "common/paths.h"
10 #include "common/pkgmgr_registration.h"
11
12 namespace bf = boost::filesystem;
13
14 namespace common_installer {
15 namespace pkgmgr {
16
17 Step::Status StepRecoverApplication::RecoveryNew() {
18   if (!SetXmlPaths())
19     return Status::OK;
20   if (context_->manifest_data.get())
21     UnregisterAppInPkgmgr(context_->manifest_data.get(),
22                           context_->pkgid.get(),
23                           context_->uid.get(),
24                           context_->request_mode.get());
25   else
26     UnregisterAppInPkgmgrForPkgId(context_->pkgid.get(),
27                                   context_->uid.get(),
28                                   context_->request_mode.get());
29   return Status::OK;
30 }
31
32 Step::Status StepRecoverApplication::RecoveryUpdate() {
33   if (!SetXmlPaths()) {
34     LOG(ERROR) << "Some parameters are lacking";
35     return Status::ERROR;
36   }
37   UnregisterAppInPkgmgr(context_->manifest_data.get(),
38                         context_->pkgid.get(),
39                         context_->uid.get(),
40                         context_->request_mode.get());
41   if (!RegisterAppInPkgmgr(context_->manifest_data.get(),
42                            context_->pkgid.get(),
43                            context_->certificate_info.get(),
44                            context_->uid.get(),
45                            context_->storage.get(),
46                            context_->request_mode.get(),
47                            context_->tep_path.get())) {
48     LOG(ERROR) << "Unsuccessful app registration";
49     return Status::RECOVERY_ERROR;
50   }
51   return Status::OK;
52 }
53
54 Step::Status StepRecoverApplication::RecoveryReadonlyUpdateInstall() {
55   // Hmm... this is just-work solution...
56   manifest_x* manifest_data = context_->manifest_data.get();
57   free(manifest_data->system);
58   manifest_data->system = strdup("true");
59   free(manifest_data->preload);
60   manifest_data->preload = strdup("true");
61   free(manifest_data->readonly);
62   manifest_data->readonly = strdup("true");
63   free(manifest_data->removable);
64   manifest_data->removable = strdup("false");
65   return RecoveryUpdate();
66 }
67
68 bool StepRecoverApplication::SetXmlPaths() {
69   if (context_->pkgid.get().empty())
70     return false;
71   bf::path xml_path =
72       bf::path(getUserManifestPath(context_->uid.get(),
73           context_->is_readonly_package.get()))
74       / context_->pkgid.get();
75   xml_path += ".xml";
76   context_->xml_path.set(xml_path);
77   context_->backup_xml_path.set(GetBackupPathForManifestFile(xml_path));
78   return true;
79 }
80
81 }  // namespace pkgmgr
82 }  // namespace common_installer