#include <manifest_parser/utils/logging.h>
+#include <filesystem>
+
#include "common/utils/byte_size_literals.h"
#include "common/utils/file_util.h"
+#include "common/utils/request.h"
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
namespace {
return (size + 1_MB - 1) / 1_MB;
}
+void ClearApp2ExtDirDetail(gpointer data) {
+ app2ext_dir_details* dir_detail =
+ reinterpret_cast<app2ext_dir_details*>(data);
+ if (dir_detail->name)
+ free(dir_detail->name);
+ free(dir_detail);
+}
+
} // namespace
namespace common_installer {
ExternalStorage::ExternalStorage(RequestType type,
const std::string& pkgid, const std::string& package_type,
- const boost::filesystem::path& application_root, uid_t uid)
+ const fs::path& application_root, uid_t uid)
: type_(type),
pkgid_(pkgid),
package_type_(package_type),
uid_(uid),
move_type_(-1),
handle_(nullptr) {
- if (package_type_ == kWgtType) {
+ if (package_type_ == kWgtType)
external_dirs_.push_back(kExternalDirForWgt);
- } else {
+ else
external_dirs_ = kExternalDirsForTpk;
- }
}
ExternalStorage::ExternalStorage(RequestType type,
const std::string& pkgid, const std::string& package_type,
- const boost::filesystem::path& application_root, uid_t uid,
+ const fs::path& application_root, uid_t uid,
bool is_external_move)
: type_(type),
pkgid_(pkgid),
application_root_(application_root),
uid_(uid),
handle_(nullptr) {
- if (package_type_ == kWgtType) {
+ if (package_type_ == kWgtType)
external_dirs_.push_back(kExternalDirForWgt);
- } else {
+ else
external_dirs_ = kExternalDirsForTpk;
- }
+
if (is_external_move)
move_type_ = APP2EXT_MOVE_TO_EXT;
else
uid_);
break;
default:
- assert(false && "Not supported installation mode");
+ LOG(ERROR) << "Not supported installation mode ("
+ << GetRequestTypeString(type_) << ")";
}
return ret == APP2EXT_STATUS_SUCCESS;
}
}
bool ExternalStorage::Initialize(
- const boost::filesystem::path& space_requirement) {
+ const fs::path& space_requirement) {
// external size in MB, set any-non zero size as default
int external_size = 1;
if (!space_requirement.empty()) {
if (package_type_ != kWgtType) {
for (auto& dir : kExternalDirsForTpk) {
- bf::path requirement = space_requirement / dir;
- if (!bf::exists(requirement))
+ fs::path requirement = space_requirement / dir;
+ if (!fs::exists(requirement))
continue;
external_size +=
SizeInMB(GetDirectorySize(requirement));
}
} else {
// for wgt whole content of package goes to res/
- external_size =
+ external_size +=
SizeInMB(GetDirectorySize(space_requirement));
}
}
- if (external_size == 0)
- external_size = 1;
-
handle_ = service.getInterfaceHandle();
if (!handle_) {
LOG(ERROR) << "app2ext_init() failed";
for (auto& dir : external_dirs_) {
app2ext_dir_details* dir_detail = reinterpret_cast<app2ext_dir_details*>(
calloc(1, sizeof(app2ext_dir_details)));
+ if (!dir_detail) {
+ LOG(ERROR) << "Out of memory";
+ g_list_free_full(glist, &ClearApp2ExtDirDetail);
+ return false;
+ }
dir_detail->name = strdup(dir.c_str());
+ if (!dir_detail->name) {
+ LOG(ERROR) << "Out of memory";
+ free(dir_detail);
+ g_list_free_full(glist, &ClearApp2ExtDirDetail);
+ return false;
+ }
dir_detail->type = APP2EXT_DIR_RO;
glist = g_list_append(glist, dir_detail);
}
ret = handle_->interface.client_usr_pre_migrate_legacy(pkgid_.c_str(),
uid_);
break;
- case RequestType::Reinstall:
- case RequestType::Recovery:
- case RequestType::ManifestDirectInstall:
- case RequestType::ManifestDirectUpdate:
- case RequestType::MountInstall:
- case RequestType::MountUpdate:
- LOG(ERROR) << "Installation type is not supported by external installation";
+ default:
+ LOG(ERROR) << "Installation type (" << GetRequestTypeString(type_) << ")"
+ << " is not supported by external installation";
ret = -1;
break;
- default:
- assert(false && "Invalid installation mode");
}
- g_list_free_full(glist, [](gpointer data) {
- app2ext_dir_details* dir_detail =
- reinterpret_cast<app2ext_dir_details*>(data);
- free(dir_detail->name);
- free(dir_detail);
- });
+ g_list_free_full(glist, &ClearApp2ExtDirDetail);
return ret == 0;
}
std::unique_ptr<ExternalStorage> ExternalStorage::MoveInstalledStorage(
- RequestType type, const boost::filesystem::path& application_root,
+ RequestType type, const fs::path& application_root,
const std::string& pkgid, const std::string& package_type,
uid_t uid, bool is_external_move) {
}
std::unique_ptr<ExternalStorage> ExternalStorage::AcquireExternalStorage(
- RequestType type, const boost::filesystem::path& application_root,
+ RequestType type, const fs::path& application_root,
const std::string& pkgid, const std::string& package_type,
- const boost::filesystem::path& space_requirement,
+ const fs::path& space_requirement,
uid_t uid) {
std::unique_ptr<ExternalStorage> external_storage(
new ExternalStorage(type, pkgid, package_type, application_root, uid));
RequestType type, const std::string& pkgid, uid_t uid) {
std::unique_ptr<ExternalStorage> external_storage(
new ExternalStorage(type, pkgid, uid));
- bf::path empty_path("");
+ fs::path empty_path("");
if (!external_storage->Initialize(empty_path)) {
LOG(WARNING) << "Cannot initialize external storage for request";
return nullptr;