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.
5 #include "common/step/filesystem/step_update_tep.h"
7 #include <pkgmgr-info.h>
9 #include <boost/filesystem.hpp>
14 #include "common/utils/paths.h"
15 #include "common/pkgmgr_registration.h"
16 #include "common/utils/file_util.h"
18 namespace bf = boost::filesystem;
19 namespace bs = boost::system;
21 namespace common_installer {
22 namespace filesystem {
24 Step::Status StepUpdateTep::precheck() {
25 if (!context_->old_manifest_data.get()) {
26 LOG(ERROR) << "Old manifest data is not set";
27 return Status::INVALID_VALUE;
29 return StepCopyTep::precheck();
32 Step::Status StepUpdateTep::process() {
33 // copy new tep file to package path if possible
34 Status status = StepCopyTep::process();
35 if (status != Status::OK)
38 // preserve old tep path if no new tep is supplied
39 if (context_->tep_path.get().empty() &&
40 context_->old_manifest_data.get()->tep_name) {
41 if (context_->manifest_data.get()->tep_name)
42 free(context_->manifest_data.get()->tep_name);
43 context_->manifest_data.get()->tep_name =
44 strdup(context_->old_manifest_data.get()->tep_name);
46 // Tep doesn't need to be copied in mount update as this mode is not
47 // creating new package directory so tep is in place.
48 if (context_->request_type.get() == RequestType::MountUpdate)
52 if (!context_->external_storage) {
53 bf::path new_path = context_->manifest_data.get()->tep_name;
54 bf::path backup_path =
56 GetBackupPathForPackagePath(context_->GetPkgPath()));
57 backup_path /= new_path.filename();
58 if (!bf::exists(new_path.parent_path())) {
60 bf::create_directory(new_path.parent_path(), error);
62 LOG(ERROR) << "Cannot recreate directory for tep file";
63 return Status::APP_DIR_ERROR;
66 if (!CopyFile(backup_path, new_path)) {
67 LOG(ERROR) << "Failed to preserve tep file during update";
68 return Status::APP_DIR_ERROR;
75 Step::Status StepUpdateTep::clean() {
76 if (context_->external_storage) {
77 if (context_->old_manifest_data.get()->tep_name &&
78 strcmp(context_->old_manifest_data.get()->tep_name,
79 context_->manifest_data.get()->tep_name)) {
80 bf::path old_tep = context_->old_manifest_data.get()->tep_name;
87 Step::Status StepUpdateTep::undo() {
88 const bf::path& remove_path = context_->tep_path.get();
89 RemoveAll(context_->old_manifest_data.get()->tep_name ?
90 remove_path : remove_path.parent_path());
94 } // namespace filesystem
95 } // namespace common_installer