Currently, ContextInstaller contains attributes (declared as private).
And each attribute has its setter and getter defined.
Property hides declaration of these setters/getters.
TODO:
* Pi (PkgmgrSignal)
Change-Id: Iba6e8a796b54468798b35e708a8ecee03ec53988
: context_(new ContextInstaller()) {
int request_type = pkgmgr_installer_get_request_type(pi);
context_->set_pi(std::unique_ptr<PkgmgrSignal>(new PkgmgrSignal(pi)));
- context_->set_request_type(request_type);
- context_->set_pkg_type(package_type);
+ context_->request_type.set(request_type);
+ context_->pkg_type.set(package_type);
switch (request_type) {
case PKGMGR_REQ_INSTALL:
- context_->set_file_path(pkgmgr_installer_get_request_info(pi));
- context_->set_pkgid(STR_EMPTY);
+ context_->file_path.set(pkgmgr_installer_get_request_info(pi));
+ context_->pkgid.set(STR_EMPTY);
break;
case PKGMGR_REQ_UNINSTALL:
- context_->set_pkgid(pkgmgr_installer_get_request_info(pi));
- context_->set_file_path(STR_EMPTY);
+ context_->pkgid.set(pkgmgr_installer_get_request_info(pi));
+ context_->file_path.set(STR_EMPTY);
break;
}
}
namespace fs = boost::filesystem;
ContextInstaller::ContextInstaller()
- : req_(PKGMGR_REQ_INVALID),
- manifest_(static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)))),
- uid_(getuid()),
- config_data_(new ConfigData()) {
+ : request_type(PKGMGR_REQ_INVALID),
+ manifest_data(static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)))),
+ uid(getuid()) {
+
+ std::string root_app_path =
+ uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+ ? tzplatform_getenv(TZ_USER_APP)
+ : tzplatform_getenv(TZ_SYS_RW_APP);
+
+ root_application_path.set(root_app_path);
+ application_path.set(
+ (fs::path(root_app_path) / fs::path(pkgid.get())).native());
}
ContextInstaller::~ContextInstaller() {
- if (manifest_)
- pkgmgr_parser_free_manifest_xml(manifest_);
-}
-
-const char* ContextInstaller::GetRootApplicationPath() const {
- return uid_ != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
- ? tzplatform_getenv(TZ_USER_APP) : tzplatform_getenv(TZ_SYS_RW_APP);
-}
-
-const char* ContextInstaller::GetApplicationPath() const {
- return (fs::path(GetRootApplicationPath()) / fs::path(pkgid())).c_str();
-}
-
-
-void ContextInstaller::set_new_temporary_pkgid() {
- static const char lookup[] =
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789";
- static const int len = 12;
- const size_t max_lookup = (sizeof(lookup)-1);
-
- std::string pkgid(len, 0);
-
- for (int i = 0; i < len-1; i++) {
- pkgid.append(1, lookup[ rand() % max_lookup ]);
- }
- set_pkgid(pkgid);
+ if (manifest_data.get())
+ pkgmgr_parser_free_manifest_xml(manifest_data.get());
}
} // namespace common_installer
namespace common_installer {
-class ConfigData;
-using ConfigDataPtr = std::unique_ptr<ConfigData>;
+/** Template class for defining smart attributes.
+ *
+ * Property should be used when, given attribute needs to have pure
+ * setter and getter. This template class will generate getter and setter.
+ * It uses operator() overloading.
+ */
+template<typename Type>
+class Property {
+ public:
+ Property() {}
+ Property(const Type &val): value_(val) { } // NOLINT
+ const Type& get() const { return value_; }
+ Type& get() { return value_; }
+ void set(const Type &val) { value_ = val; }
+ private:
+ Type value_;
+};
class ConfigData {
public:
ConfigData() {}
-
- std::string application_name() const { return application_name_; }
- void set_application_name(const std::string& app_name) {
- application_name_ = app_name;
- }
- std::string required_version() const { return required_version_; }
- void set_required_version(const std::string& required_version) {
- required_version_ = required_version;
- }
-
- private:
- std::string application_name_;
- std::string required_version_;
+ Property<std::string> application_name;
+ Property<std::string> required_version;
};
// TODO(p.sikorski@samsung.com) this class should be divided into:
ContextInstaller();
~ContextInstaller();
- int request_type() const { return req_; }
- void set_request_type(int req) {
- req_ = req;
- }
-
- std::string pkg_type() const { return pkg_type_; }
- void set_pkg_type(const std::string& pkg_type) {
- pkg_type_ = pkg_type;
- }
-
- manifest_x* manifest_data() const { return manifest_; }
- void set_manifest(manifest_x* manifest) {
- manifest_ = manifest;
- }
-
- std::string xml_path() const { return xml_path_; }
- void set_xml_path(const std::string& xml) {
- xml_path_ = xml;
- }
-
- std::string pkgid() const { return pkgid_; }
- void set_pkgid(const std::string& pkgid) {
- pkgid_ = pkgid;
- }
- void set_new_temporary_pkgid(void);
-
- std::string pkg_path() const { return pkg_path_; }
- void set_pkg_path(const std::string& package_path) {
- pkg_path_ = package_path;
- }
-
- std::string file_path() const { return file_path_; }
- void set_file_path(const std::string& file_path) {
- file_path_ = file_path;
- }
-
- void set_pi(std::unique_ptr<PkgmgrSignal> pi) {
- pi_ = std::move(pi);
- }
-
- uid_t uid() const { return uid_; }
-
- std::string unpacked_dir_path() const { return unpacked_dir_path_; }
- void set_unpacked_dir_path(const std::string& dir_path) {
- unpacked_dir_path_ = dir_path;
- }
-
- ConfigData* config_data() const { return config_data_.get(); }
-
- PkgmgrSignal* pi() const { return pi_.get(); }
-
- const char* GetApplicationPath() const;
- const char* GetRootApplicationPath() const;
-
- private :
// request type: Install, Reinstall, Uninstall, Update.
- int req_;
+ Property<int> request_type;
+
+ // package_type
+ Property<std::string> pkg_type;
// manifest information used to generate xml file
- manifest_x* manifest_;
+ Property<manifest_x*> manifest_data;
// path to manifest xml file used to register data in databases
- std::string xml_path_;
+ Property<std::string> xml_path;
// pkgid used for update or uninstallation processing
- std::string pkgid_;
-
- // package_type
- std::string pkg_type_;
-
- // uid of the user that request the operation
- uid_t uid_;
+ Property<std::string> pkgid;
// package directory path containing app data
- std::string pkg_path_;
+ Property<std::string> pkg_path;
// file path used for installation or reinstallation process
- std::string file_path_;
+ Property<std::string> file_path;
// directory path where app data are temporarily extracted
- std::string unpacked_dir_path_;
+ Property<std::string> unpacked_dir_path;
+
+ // uid of the user that request the operation
+ Property<uid_t> uid;
+
// data from config.xml
- ConfigDataPtr config_data_;
+ Property<ConfigData> config_data;
+
+ // TODO(p.sikorski@samsung.com) change "pi" to Property
+ PkgmgrSignal* pi() const { return pi_.get(); }
+ void set_pi(std::unique_ptr<PkgmgrSignal> pi) {
+ pi_ = std::move(pi);
+ }
+ // path for the applications directory
+ Property<std::string> application_path;
+
+ // path for the applications root directory
+ Property<std::string> root_application_path;
+
+ private :
// data used to send signal
std::unique_ptr<PkgmgrSignal> pi_;
};
namespace signature {
Step::Status StepCheckSignature::process() {
- return (SignatureValidator::Check(bf::path(context_->unpacked_dir_path()))
+ return (SignatureValidator::Check(bf::path(context_->unpacked_dir_path.get()))
== SignatureValidator::INVALID) ? Status::ERROR : Status::OK;
}
namespace bs = boost::system;
Step::Status StepCopy::process() {
- assert(!context_->pkgid().empty());
+ assert(!context_->pkgid.get().empty());
- bf::path install_path = bf::path(context_->GetApplicationPath());
+ bf::path install_path = bf::path(context_->application_path.get());
- context_->set_pkg_path(install_path.string());
+ context_->pkg_path.set(install_path.string());
// FIXME: correctly order app's data.
// If there is 1 app in package, app's data are stored in <pkg_path>/<app_id>
// If there are >1 apps in package, app's data are stored in <pkg_path>
// considering that multiple apps data are already separated in folders.
- if (context_->manifest_data()->uiapplication &&
- !context_->manifest_data()->uiapplication->next)
- install_path /= bf::path(context_->manifest_data()->mainapp_id);
+ if (context_->manifest_data.get()->uiapplication &&
+ !context_->manifest_data.get()->uiapplication->next)
+ install_path /= bf::path(context_->manifest_data.get()->mainapp_id);
bs::error_code error;
bf::create_directories(install_path.parent_path(), error);
<< install_path.parent_path().string();
return Step::Status::ERROR;
}
- bf::rename(context_->unpacked_dir_path(), install_path, error);
+ bf::rename(context_->unpacked_dir_path.get(), install_path, error);
if (error) {
LOG(DEBUG) << "Cannot move directory. Will try to copy...";
- if (!utils::CopyDir(bf::path(context_->unpacked_dir_path()),
+ if (!utils::CopyDir(bf::path(context_->unpacked_dir_path.get()),
install_path)) {
- LOG(ERROR) << "Fail to copy tmp dir: " << context_->unpacked_dir_path()
- << " to dst dir: " << install_path.string();
+ LOG(ERROR) << "Fail to copy tmp dir: "
+ << context_->unpacked_dir_path.get()
+ << " to dst dir: " << install_path.string();
return Step::Status::ERROR;
}
bs::error_code error;
- bf::remove_all(context_->unpacked_dir_path(), error);
+ bf::remove_all(context_->unpacked_dir_path.get(), error);
if (error) {
LOG(WARNING) << "Cannot remove temporary directory: "
- << context_->unpacked_dir_path();
+ << context_->unpacked_dir_path.get();
}
}
- LOG(INFO) << "Successfully move/copy: " << context_->unpacked_dir_path()
+ LOG(INFO) << "Successfully move/copy: " << context_->unpacked_dir_path.get()
<< " to: " << install_path.string() << " directory";
return Status::OK;
}
}
Step::Status StepCopy::undo() {
- if (bf::exists(context_->pkg_path()))
- bf::remove_all(context_->pkg_path());
+ if (bf::exists(context_->pkg_path.get()))
+ bf::remove_all(context_->pkg_path.get());
return Status::OK;
}
namespace generate_xml {
Step::Status StepGenerateXml::process() {
- assert(context_->manifest_data());
+ assert(context_->manifest_data.get());
- fs::path xml_path = fs::path(getUserManifestPath(context_->uid()))
- / fs::path(context_->pkgid());
+ fs::path xml_path = fs::path(getUserManifestPath(context_->uid.get()))
+ / fs::path(context_->pkgid.get());
xml_path += ".xml";
- context_->set_xml_path(xml_path.string());
+ context_->xml_path.set(xml_path.string());
boost::system::error_code error;
- if ((!context_->manifest_data()->uiapplication) &&
- (!context_->manifest_data()->serviceapplication)) {
+ if ((!context_->manifest_data.get()->uiapplication) &&
+ (!context_->manifest_data.get()->serviceapplication)) {
LOG(ERROR) << "There is neither UI applications nor"
<< "Services applications described!";
return Step::Status::ERROR;
xmlTextWriterPtr writer;
- writer = xmlNewTextWriterFilename(context_->xml_path().c_str(), 0);
+ writer = xmlNewTextWriterFilename(context_->xml_path.get().c_str(), 0);
if (!writer) {
LOG(ERROR) << "Failed to create new file";
return Step::Status::ERROR;
xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns",
BAD_CAST "http://tizen.org/ns/packages");
xmlTextWriterWriteAttribute(writer, BAD_CAST "package",
- BAD_CAST context_->manifest_data()->package);
+ BAD_CAST context_->manifest_data.get()->package);
xmlTextWriterWriteAttribute(writer, BAD_CAST "type",
- BAD_CAST context_->manifest_data()->type);
+ BAD_CAST context_->manifest_data.get()->type);
xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
- BAD_CAST context_->manifest_data()->version);
+ BAD_CAST context_->manifest_data.get()->version);
- if ( context_->manifest_data()->description &&
- context_->manifest_data()->description->name )
+ if ( context_->manifest_data.get()->description &&
+ context_->manifest_data.get()->description->name )
xmlTextWriterWriteFormatElement(writer, BAD_CAST "description",
- "%s", BAD_CAST context_->manifest_data()->description->name);
+ "%s", BAD_CAST context_->manifest_data.get()->description->name);
else
xmlTextWriterWriteFormatElement(writer, BAD_CAST "description",
"%s", BAD_CAST "");
// add ui-application element per ui application
- for (uiapplication_x* ui = context_->manifest_data()->uiapplication;
+ for (uiapplication_x* ui = context_->manifest_data.get()->uiapplication;
ui != nullptr; ui = ui->next) {
xmlTextWriterStartElement(writer, BAD_CAST "ui-application");
BAD_CAST ui->appid);
// binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
- fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(ui->appid)
- / fs::path("bin") / fs::path(ui->appid);
+ fs::path exec_path =
+ fs::path(context_->pkg_path.get()) / fs::path(ui->appid)
+ / fs::path("bin") / fs::path(ui->appid);
xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
BAD_CAST exec_path.string().c_str());
// the icon is renamed to <appid.png>
// and located in TZ_USER_ICON/TZ_SYS_ICON
// if the icon isn't exist print the default icon app-installers.png
- icon_path_ = fs::path(getIconPath(context_->uid()));
+ icon_path_ = fs::path(getIconPath(context_->uid.get()));
utils::CreateDir(icon_path_);
fs::path icon = fs::path(ui->appid) += fs::path(".png");
if (ui->icon && ui->icon->name) {
- fs::path app_icon = fs::path(context_->pkg_path()) / fs::path(ui->appid)
- / fs::path(ui->icon->name);
+ fs::path app_icon = fs::path(context_->pkg_path.get())
+ / fs::path(ui->appid) / fs::path(ui->icon->name);
if (fs::exists(app_icon))
fs::rename(app_icon, icon_path_ /= icon);
} else {
// add service-application element per service application
for (serviceapplication_x* svc =
- context_->manifest_data()->serviceapplication;
+ context_->manifest_data.get()->serviceapplication;
svc != nullptr; svc = svc->next) {
xmlTextWriterStartElement(writer, BAD_CAST "service-application");
xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", BAD_CAST svc->appid);
// binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
- fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(svc->appid)
- / fs::path("bin") / fs::path(svc->appid);
+ fs::path exec_path =
+ fs::path(context_->pkg_path.get()) / fs::path(svc->appid)
+ / fs::path("bin") / fs::path(svc->appid);
xmlTextWriterWriteAttribute(writer, BAD_CAST "exec",
BAD_CAST exec_path.string().c_str());
// the icon is renamed to <appid.png>
// and located in TZ_USER_ICON/TZ_SYS_ICON
// if the icon isn't exist print the default icon app-installers.png
- icon_path_ = fs::path(getIconPath(context_->uid()));
+ icon_path_ = fs::path(getIconPath(context_->uid.get()));
utils::CreateDir(icon_path_);
fs::path icon = fs::path(svc->appid) += fs::path(".png");
if (svc->icon && svc->icon->name) {
- fs::path app_icon = fs::path(context_->pkg_path()) / fs::path(svc->appid)
- / fs::path(svc->icon->name);
+ fs::path app_icon =
+ fs::path(context_->pkg_path.get()) / fs::path(svc->appid)
+ / fs::path(svc->icon->name);
if (fs::exists(app_icon))
fs::rename(app_icon, icon_path_ /= icon);
} else {
// add privilege element
privileges_x* pvlg = nullptr;
- PKGMGR_LIST_MOVE_NODE_TO_HEAD(context_->manifest_data()->privileges, pvlg);
+ PKGMGR_LIST_MOVE_NODE_TO_HEAD(
+ context_->manifest_data.get()->privileges,
+ pvlg);
for (; pvlg != nullptr; pvlg = pvlg->next) {
xmlTextWriterStartElement(writer, BAD_CAST "privileges");
privilege_x* pv = nullptr;
xmlFreeTextWriter(writer);
if (pkgmgr_parser_check_manifest_validation(
- context_->xml_path().c_str()) != 0) {
+ context_->xml_path.get().c_str()) != 0) {
LOG(ERROR) << "Manifest is not valid";
return Step::Status::ERROR;
}
- LOG(DEBUG) << "Successfully create manifest xml " << context_->xml_path();
+ LOG(DEBUG) << "Successfully create manifest xml "
+ << context_->xml_path.get();
return Status::OK;
}
namespace fs = boost::filesystem;
Step::Status StepParse::process() {
- fs::path xml_path = fs::path(getUserManifestPath(context_->uid()))
- / fs::path(context_->pkgid());
+ fs::path xml_path = fs::path(getUserManifestPath(context_->uid.get()))
+ / fs::path(context_->pkgid.get());
xml_path += ".xml";
- context_->set_xml_path(xml_path.string());
+ context_->xml_path.set(xml_path.string());
xmlInitParser();
manifest_x* mfx = pkgmgr_parser_usr_process_manifest_xml(
- context_->xml_path().c_str(), context_->uid());
+ context_->xml_path.get().c_str(), context_->uid.get());
if (!mfx) {
- LOG(ERROR) << "Failed to parse tizen manifest xml " << context_->xml_path();
+ LOG(ERROR) << "Failed to parse tizen manifest xml "
+ << context_->xml_path.get();
return Step::Status::ERROR;
}
- context_->set_manifest(mfx);
- context_->set_pkg_path(context_->GetApplicationPath());
+ context_->manifest_data.set(mfx);
+ context_->pkg_path.set(context_->application_path.get());
LOG(DEBUG) << "Successfully parse tizen manifest xml";
#include <pkgmgr-info.h>
#include <unistd.h>
-
#include <boost/filesystem.hpp>
#include <cassert>
#include <cstring>
namespace fs = boost::filesystem;
Step::Status StepRegisterApplication::process() {
- assert(!context_->xml_path().empty());
+ assert(!context_->xml_path.get().empty());
const char* const appinst_tags[] = {"removable=true", nullptr, };
// TODO(sdi2): Check if data->removable is correctly setting
// Having a specific step to implement a installer commandline tool
// for image build could be usefull also.
- int ret = context_->uid() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ?
+ int ret = context_->uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ?
pkgmgr_parser_parse_usr_manifest_for_installation(
- context_->xml_path().c_str(), context_->uid(),
+ context_->xml_path.get().c_str(), context_->uid.get(),
const_cast<char* const*>(appinst_tags)) :
pkgmgr_parser_parse_manifest_for_installation(
- context_->xml_path().c_str(), const_cast<char* const*>(appinst_tags));
+ context_->xml_path.get().c_str(),
+ const_cast<char* const*>(appinst_tags));
if (ret != 0) {
LOG(ERROR) << "Failed to record package into database";
}
Step::Status StepRegisterApplication::undo() {
- if (context_->uid() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
+ if (context_->uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
const char* ail_cmd[] = {kAilInitUser, nullptr};
const char* pkgmgr_cmd[] = {kPkgInitUser, nullptr};
Step::Status StepRegisterSecurity::process() {
if (!RegisterSecurityContextForApps(
- context_->pkgid(), context_->GetApplicationPath(),
- context_->manifest_data())) {
+ context_->pkgid.get(), context_->application_path.get(),
+ context_->manifest_data.get())) {
return Status::ERROR;
}
LOG(DEBUG) << "Security context installed";
Step::Status StepRegisterSecurity::undo() {
if (!UnregisterSecurityContextForApps(
- context_->pkgid(), context_->manifest_data())) {
+ context_->pkgid.get(), context_->manifest_data.get())) {
return Status::ERROR;
}
LOG(DEBUG) << "Security context uninstalled";
namespace fs = boost::filesystem;
Step::Status StepRemoveFiles::process() {
- uiapplication_x* ui = context_->manifest_data()->uiapplication;
+ uiapplication_x* ui = context_->manifest_data.get()->uiapplication;
- if (!fs::exists(context_->pkg_path()))
- LOG(DEBUG) << "dir: " << context_->pkg_path() << "not exist";
+ if (!fs::exists(context_->pkg_path.get()))
+ LOG(DEBUG) << "dir: " << context_->pkg_path.get() << "not exist";
- fs::remove_all(context_->pkg_path());
+ fs::remove_all(context_->pkg_path.get());
for (; ui != nullptr; ui = ui->next) {
- fs::path app_icon = fs::path(getIconPath(context_->uid()))
+ fs::path app_icon = fs::path(getIconPath(context_->uid.get()))
/ fs::path(ui->appid);
app_icon += fs::path(".png");
if (fs::exists(app_icon))
fs::remove_all(app_icon);
}
- fs::remove_all(context_->xml_path());
+ fs::remove_all(context_->xml_path.get());
- LOG(DEBUG) << "Removing dir: " << context_->pkg_path();
+ LOG(DEBUG) << "Removing dir: " << context_->pkg_path.get();
return Status::OK;
}
Step::Status StepRevokeSecurity::process() {
if (!UnregisterSecurityContextForApps(
- context_->pkgid(), context_->manifest_data())) {
+ context_->pkgid.get(), context_->manifest_data.get())) {
LOG(ERROR) << "Failure on unregistering security context for app "
- << context_->pkgid();
+ << context_->pkgid.get();
return Status::ERROR;
}
LOG(DEBUG) << "Security context uninstalled";
Step::Status StepRevokeSecurity::undo() {
if (!RegisterSecurityContextForApps(
- context_->pkgid(), context_->GetApplicationPath(),
- context_->manifest_data())) {
+ context_->pkgid.get(), context_->application_path.get(),
+ context_->manifest_data.get())) {
LOG(ERROR) << "Failure on re-installing security context for app "
- << context_->pkgid();
+ << context_->pkgid.get();
return Status::ERROR;
}
LOG(DEBUG) << "Security context installed";
Step::Status StepSignal::process() {
if (!context_->pi()->sendStarted(
- context_->manifest_data()->type, context_->pkgid())) {
+ context_->manifest_data.get()->type, context_->pkgid.get())) {
return Status::ERROR;
}
LOG(DEBUG) << "Send Start";
Step::Status StepSignal::clean() {
if (!context_->pi()->sendFinished(
PkgmgrSignal::Result::SUCCESS,
- context_->manifest_data()->type, context_->pkgid())) {
+ context_->manifest_data.get()->type, context_->pkgid.get())) {
return Status::ERROR;
}
LOG(DEBUG) << "Send Success";
Step::Status StepSignal::undo() {
if (!context_->pi()->sendFinished(
PkgmgrSignal::Result::FAILED,
- context_->manifest_data()->type, context_->pkgid())) {
+ context_->manifest_data.get()->type, context_->pkgid.get())) {
return Status::ERROR;
}
LOG(ERROR) << "Send Error";
Status process() override;
Status clean() override;
Status undo() override;
-
private:
- bool sendSignal(ContextInstaller* data, const std::string& key,
- const std::string& value);
-
SCOPE_LOG_TAG(Signal)
};
namespace fs = boost::filesystem;
Step::Status StepUnregisterApplication::process() {
- assert(!context_->pkgid().empty());
+ assert(!context_->pkgid.get().empty());
const char* const appinst_tags[] = {"removable=true", nullptr, };
- int ret = context_->uid() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ?
+ int ret = context_->uid.get() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ?
pkgmgr_parser_parse_usr_manifest_for_uninstallation(
- context_->xml_path().c_str(), context_->uid(),
+ context_->xml_path.get().c_str(), context_->uid.get(),
const_cast<char* const*>(appinst_tags)) :
pkgmgr_parser_parse_manifest_for_uninstallation(
- context_->xml_path().c_str(), const_cast<char* const*>(appinst_tags));
+ context_->xml_path.get().c_str(),
+ const_cast<char* const*>(appinst_tags));
if (ret != 0) {
LOG(ERROR) << "Failed to unregister package into database";
: Step(context),
is_extracted_(false) {}
-boost::filesystem::path StepUnzip::GenerateTmpDir(const char* app_path) {
+boost::filesystem::path StepUnzip::GenerateTmpDir(const std::string &app_path) {
boost::filesystem::path install_tmp_dir;
boost::filesystem::path tmp_dir(app_path);
}
Step::Status StepUnzip::process() {
- assert(!context_->file_path().empty());
- assert(!access(context_->file_path().c_str(), F_OK));
+ assert(!context_->file_path.get().empty());
+ assert(!access(context_->file_path.get().c_str(), F_OK));
bf::path tmp_dir =
- GenerateTmpDir(context_->GetRootApplicationPath());
+ GenerateTmpDir(context_->root_application_path.get());
if (!utils::CreateDir(tmp_dir)) {
LOG(ERROR) << "Failed to create temp directory: " << tmp_dir;
}
int64_t required_size =
- GetUnpackedPackageSize(bf::path(context_->file_path()));
+ GetUnpackedPackageSize(bf::path(context_->file_path.get()));
if (required_size == -1) {
LOG(ERROR) << "Couldn't get uncompressed size for package: "
- << context_->file_path();
+ << context_->file_path.get();
return Step::Status::ERROR;
}
}
if (!CheckFreeSpaceAtPath(required_size,
- bf::path(context_->GetRootApplicationPath()))) {
+ bf::path(context_->root_application_path.get()))) {
LOG(ERROR) << "There is not enough space to install application files";
return Step::Status::OUT_OF_SPACE;
}
- if (ExtractToTmpDir(context_->file_path().c_str(), tmp_dir)
+ if (ExtractToTmpDir(context_->file_path.get().c_str(), tmp_dir)
!= Step::Status::OK) {
LOG(ERROR) << "Failed to process unpack step";
return Step::Status::ERROR;
}
- context_->set_unpacked_dir_path(tmp_dir.string());
+ context_->unpacked_dir_path.set(tmp_dir.string());
- LOG(INFO) << context_->file_path() << " was successfully unzipped into "
- << context_->unpacked_dir_path();
+ LOG(INFO) << context_->file_path.get() << " was successfully unzipped into "
+ << context_->unpacked_dir_path.get();
return Status::OK;
}
Step::Status StepUnzip::undo() {
- if (access(context_->unpacked_dir_path().c_str(), F_OK) == 0) {
- bf::remove_all(context_->unpacked_dir_path());
- LOG(DEBUG) << "remove temp dir: " << context_->unpacked_dir_path();
+ if (access(context_->unpacked_dir_path.get().c_str(), F_OK) == 0) {
+ bf::remove_all(context_->unpacked_dir_path.get());
+ LOG(DEBUG) << "remove temp dir: " << context_->unpacked_dir_path.get();
}
return Status::OK;
}
#include <boost/filesystem/path.hpp>
+#include <string>
+
#include "common/context_installer.h"
#include "common/step/step.h"
#include "utils/logging.h"
Status undo() override;
private:
- boost::filesystem::path GenerateTmpDir(const char* app_path);
+ boost::filesystem::path GenerateTmpDir(const std::string &app_path);
Step::Status ExtractToTmpDir(const char* source_dir,
const boost::filesystem::path& tmp_dir);
boost::system::error_code error;
for (; app != nullptr; app=app->next) {
- fs::path bindir = fs::path(context->pkg_path()) / fs::path(app->appid) /
+ fs::path bindir = fs::path(context->pkg_path.get()) / fs::path(app->appid) /
fs::path("bin");
LOG(INFO) << "Creating dir: " << bindir;
if (!common_installer::utils::CreateDir(bindir)) {
* So we don't remove the bin/ directory itself.
*/
for (; app != nullptr; app=app->next) {
- fs::path exec_path = fs::path(context->pkg_path()) /
+ fs::path exec_path = fs::path(context->pkg_path.get()) /
fs::path(app->appid) / fs::path("bin");
fs::remove_all(exec_path / fs::path(app->appid));
}
Status StepCreateSymbolicLink::process() {
// Get manifest_x
- manifest_x *m = context_->manifest_data();
+ manifest_x *m = context_->manifest_data.get();
if (!m) {
LOG(ERROR) << "manifest_x is null";
return Status::ERROR;
Status StepCreateSymbolicLink::undo() {
- manifest_x* m = context_->manifest_data();
+ manifest_x* m = context_->manifest_data.get();
uiapplication_x *uiapp = m->uiapplication;
serviceapplication_x *svcapp = m->serviceapplication;
if (!RemoveSymLink(uiapp, context_)) return Status::ERROR;
*/
Status StepParse::process() {
std::unique_ptr<boost::filesystem::path> mPath(
- GetManifestFilePath(context_->unpacked_dir_path()));
+ GetManifestFilePath(context_->unpacked_dir_path.get()));
if (!mPath) {
return Status::ERROR;
}
}
// set context_
- context_->config_data()->set_application_name(label->content());
- context_->config_data()->set_required_version(manifest->attr("api_version"));
- context_->set_pkgid(manifest->attr("package"));
- context_->set_manifest(static_cast<manifest_x*>(
+ context_->config_data.get().application_name.set(label->content());
+ context_->config_data.get().required_version.set(
+ manifest->attr("api_version"));
+ context_->pkgid.set(manifest->attr("package"));
+ context_->manifest_data.set(static_cast<manifest_x*>(
calloc(1, sizeof(manifest_x))));
// set context_->manifest_data()
- return SetPkgInfoManifest(context_->manifest_data(), tree, manifest);
+ return SetPkgInfoManifest(context_->manifest_data.get(), tree, manifest);
}
namespace fs = boost::filesystem;
common_installer::Step::Status StepCreateSymbolicLink::process() {
- assert(context_->manifest_data());
+ assert(context_->manifest_data.get());
boost::system::error_code error;
- uiapplication_x* ui = context_->manifest_data()->uiapplication;
- serviceapplication_x* svc = context_->manifest_data()->serviceapplication;
+ uiapplication_x* ui = context_->manifest_data.get()->uiapplication;
+ serviceapplication_x* svc =
+ context_->manifest_data.get()->serviceapplication;
if ((!ui) && (!svc)) {
LOG(ERROR) << "There is neither UI applications nor"
<< "Services applications described!";
// add ui-application element per ui application
for (; ui != nullptr; ui = ui->next) {
// binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
- fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(ui->appid)
- / fs::path("bin");
+ fs::path exec_path =
+ fs::path(context_->pkg_path.get()) / fs::path(ui->appid)
+ / fs::path("bin");
common_installer::utils::CreateDir(exec_path);
exec_path /= fs::path(ui->appid);
}
for (; svc != nullptr; svc = svc->next) {
// binary is a symbolic link named <appid> and is located in <pkgid>/<appid>
- fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(svc->appid)
- / fs::path("bin");
+ fs::path exec_path =
+ fs::path(context_->pkg_path.get()) / fs::path(svc->appid)/
+ fs::path("bin");
common_installer::utils::CreateDir(exec_path);
exec_path /= fs::path(svc->appid);
}
common_installer::Step::Status StepCreateSymbolicLink::undo() {
- uiapplication_x* ui = context_->manifest_data()->uiapplication;
- serviceapplication_x* svc = context_->manifest_data()->serviceapplication;
+ uiapplication_x* ui = context_->manifest_data.get()->uiapplication;
+ serviceapplication_x* svc = context_->manifest_data.get()->serviceapplication;
for (; ui != nullptr; ui = ui->next) {
- fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(ui->appid)
- / fs::path("bin");
+ fs::path exec_path =
+ fs::path(context_->pkg_path.get()) / fs::path(ui->appid)
+ / fs::path("bin");
if (fs::exists(exec_path))
fs::remove_all(exec_path);
}
for (; svc != nullptr; svc = svc->next) {
- fs::path exec_path = fs::path(context_->pkg_path()) / fs::path(svc->appid)
- / fs::path("bin");
+ fs::path exec_path =
+ fs::path(context_->pkg_path.get()) / fs::path(svc->appid)
+ / fs::path("bin");
if (fs::exists(exec_path))
fs::remove_all(exec_path);
}
}
common_installer::Step::Status StepParse::process() {
- if (!StepParse::Check(context_->unpacked_dir_path())) {
+ if (!StepParse::Check(context_->unpacked_dir_path.get())) {
LOG(ERROR) << "No config.xml";
return common_installer::Step::Status::ERROR;
}
return common_installer::Step::Status::ERROR;
}
- const manifest_x* manifest = context_->manifest_data();
+ const manifest_x* manifest = context_->manifest_data.get();
if (!FillManifestX(const_cast<manifest_x*>(manifest))) {
LOG(ERROR) << "[Parse] Storing manifest_x failed. "
<< parser_->GetErrorMessage();
app_keys::kVersionKey, &version);
required_api_version = info->required_version();
- context_->config_data()->set_application_name(
+ context_->config_data.get().application_name.set(
std::string(manifest->uiapplication->label->name));
- context_->set_pkgid(std::string(manifest->package));
- context_->config_data()->set_required_version(required_api_version);
+ context_->config_data.get().required_version.set(required_api_version);
+ context_->pkgid.set(std::string(manifest->package));
std::shared_ptr<const PermissionsInfo> perm_info =
std::static_pointer_cast<const PermissionsInfo>(