#include <cassert>
#include <cstring>
+#include <filesystem>
#include <string>
+#include <system_error>
+#include "common/utils/paths.h"
#include "common/utils/file_util.h"
namespace common_installer {
namespace filesystem {
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
+namespace fs = std::filesystem;
Step::Status StepCopyTep::precheck() {
if (context_->root_application_path.get().empty()) {
return Step::Status::INVALID_VALUE;
}
- if (!boost::filesystem::exists(context_->root_application_path.get())) {
+ if (!std::filesystem::exists(context_->root_application_path.get())) {
LOG(ERROR) << "root_application_path ("
<< context_->root_application_path.get()
<< ") path does not exist";
Step::Status StepCopyTep::process() {
if (context_->tep_path.get().empty())
return Step::Status::OK;
+ fs::path tep_path;
+ if (context_->external_storage) {
+ tep_path = GetExternalTepPath(context_->request_mode.get(),
+ context_->uid.get());
+ } else {
+ tep_path = GetInternalTepPath(context_->GetPkgPath());
+ }
- context_->pkg_path.set(
- context_->root_application_path.get() / context_->pkgid.get());
+ // Keep filename of app store supplied file. Filename contains hash that
+ // appstore uses to identify version of tep on device.
+ tep_path /= context_->tep_path.get().filename();
- bf::path tep_path =
- context_->pkg_path.get() / "tep" / context_->tep_path.get().filename();
+ if (!fs::exists(tep_path.parent_path())) {
+ std::error_code error;
+ fs::create_directories(tep_path.parent_path(), error);
+ if (error) {
+ LOG(ERROR) << "Cannot create tep parent directory";
+ return Status::APP_DIR_ERROR;
+ }
+ }
if (context_->is_tep_move.get()) {
if (!MoveFile(context_->tep_path.get(), tep_path)) {
}
Step::Status StepCopyTep::undo() {
- if (bf::exists(context_->tep_path.get()))
- bf::remove_all(context_->tep_path.get());
+ RemoveAll(context_->tep_path.get());
+ // remove tep file is installed outside package path
+ if (context_->external_storage) {
+ fs::path tep_path = GetExternalTepPath(context_->request_mode.get(),
+ context_->uid.get());
+ tep_path /= context_->tep_path.get().filename();
+ RemoveAll(tep_path);
+ }
return Status::OK;
}