+++ /dev/null
-// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#include "common/step/filesystem/step_create_per_user_storage_directories.h"
-
-#include <string>
-#include <vector>
-
-#include "common/privileges.h"
-
-#include "common/shared_dirs.h"
-#include "common/utils/glist_range.h"
-
-namespace common_installer {
-namespace filesystem {
-
-Step::Status StepCreatePerUserStorageDirectories::process() {
- if (context_->request_mode.get() != RequestMode::GLOBAL)
- return Step::Status::OK;
-
- std::string package_id = context_->pkgid.get();
- LOG(INFO) << "Creating per-user directories for package: " << package_id;
-
- manifest_x* manifest = context_->manifest_data.get();
- std::string str_ver(manifest->api_version);
- std::string author_id = context_->certificate_info.get().author_id.get();
- bool trusted = false;
- if (!author_id.empty())
- trusted = true;
-
- bool shareddata = false;
- for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
- if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
- shareddata = true;
- break;
- }
- }
- if (!common_installer::CreateSkelDirectories(package_id,
- str_ver, trusted, shareddata, context_->is_readonly_package.get(),
- additional_shared_dirs_)) {
- LOG(ERROR) << "Failed to create skel dirs";
- return Status::APP_DIR_ERROR;
- }
-
- if (!CopyUserDirectories(package_id)) {
- LOG(ERROR) << "Failed to create shared dirs for users";
- return Status::APP_DIR_ERROR;
- }
-
- return Status::OK;
-}
-
-Step::Status StepCreatePerUserStorageDirectories::undo() {
- if (context_->request_mode.get() != RequestMode::GLOBAL)
- return Step::Status::OK;
-
- if (!DeleteSkelDirectories(context_->pkgid.get()))
- return Status::APP_DIR_ERROR;
-
- if (!DeleteUserDirectories(context_->pkgid.get()))
- return Status::APP_DIR_ERROR;
-
- return Status::OK;
-}
-
-} // namespace filesystem
-} // namespace common_installer
+++ /dev/null
-// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef COMMON_STEP_FILESYSTEM_STEP_CREATE_PER_USER_STORAGE_DIRECTORIES_H_
-#define COMMON_STEP_FILESYSTEM_STEP_CREATE_PER_USER_STORAGE_DIRECTORIES_H_
-
-#include <manifest_parser/utils/logging.h>
-
-#include <vector>
-
-#include "common/step/step.h"
-
-namespace common_installer {
-namespace filesystem {
-
-/**
- * \brief Installation.
- * Responsible for creating shared and data directories for users (wgt/tpk)
- *
- * * process method implements creation of data and shared directories for
- * package in case of global installation for each user. Normally,
- * "storage"/"shared" directories are created in StepCreateStorageDirectories.
- *
- * * Other methods are empty.
- */
-class StepCreatePerUserStorageDirectories : public common_installer::Step {
- public:
- using Step::Step;
-
- explicit StepCreatePerUserStorageDirectories(InstallerContext* context)
- : Step(context), additional_shared_dirs_(std::vector<const char*>()) {}
-
- StepCreatePerUserStorageDirectories(InstallerContext* context,
- const std::vector<const char*> additional_shared_dirs)
- : Step(context), additional_shared_dirs_(additional_shared_dirs) {}
-
- Status process() override;
- Status clean() override { return Status::OK; }
- Status undo() override;
- Status precheck() override { return Status::OK; }
-
- private:
- const std::vector<const char*> additional_shared_dirs_;
-
- STEP_NAME(CreatePerUserStorageDirectories)
-};
-
-} // namespace filesystem
-} // namespace common_installer
-
-#endif // COMMON_STEP_FILESYSTEM_STEP_CREATE_PER_USER_STORAGE_DIRECTORIES_H_
namespace common_installer {
namespace filesystem {
-common_installer::Step::Status StepCreateStorageDirectories::process() {
+bool StepCreateStorageDirectories::CreatePerUserStorageDirectories() {
+ std::string package_id = context_->pkgid.get();
+ std::string author_id = context_->certificate_info.get().author_id.get();
+ manifest_x* manifest = context_->manifest_data.get();
+ bool is_readonly = context_->is_readonly_package.get();
+
+ LOG(INFO) << "Creating per-user directories for package: " << package_id;
+
+ std::string str_ver(manifest->api_version);
+ bool trusted = false;
+ if (!author_id.empty())
+ trusted = true;
+
+ bool shareddata = false;
+ for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
+ if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
+ shareddata = true;
+ break;
+ }
+ }
+ if (!CreateSkelDirectories(package_id,
+ str_ver, trusted, shareddata, is_readonly,
+ additional_shared_dirs_)) {
+ LOG(ERROR) << "Failed to create skel dirs";
+ return false;
+ }
+
+ if (!CopyUserDirectories(package_id)) {
+ LOG(ERROR) << "Failed to create shared dirs for users";
+ return false;
+ }
+
+ return true;
+}
+
+Step::Status StepCreateStorageDirectories::process() {
if (context_->request_mode.get() == RequestMode::GLOBAL) {
// remove packaged RW diriectories
- if (!common_installer::DeleteStorageDirectories(context_->GetPkgPath())) {
+ if (!DeleteStorageDirectories(context_->GetPkgPath())) {
LOG(ERROR) << "Failed to remove storage directories";
return Status::APP_DIR_ERROR;
}
- return Status::OK;
- }
- manifest_x* manifest = context_->manifest_data.get();
- bool has_priv = false;
- for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
- if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
- has_priv = true;
- break;
+ if (!CreatePerUserStorageDirectories())
+ return Status::APP_DIR_ERROR;
+ } else {
+ manifest_x* manifest = context_->manifest_data.get();
+ bool has_priv = false;
+ for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
+ if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
+ has_priv = true;
+ break;
+ }
+ }
+ if (!CreateStorageDirectories(context_->GetPkgPath(), manifest->api_version,
+ true, has_priv)) {
+ LOG(ERROR) << "Failed to create storage directories";
+ return Status::APP_DIR_ERROR;
}
}
- if (!common_installer::CreateStorageDirectories(context_->GetPkgPath(),
- manifest->api_version,
- true, has_priv)) {
- LOG(ERROR) << "Failed to create storage directories";
+ return Status::OK;
+}
+
+Step::Status StepCreateStorageDirectories::undo() {
+ if (context_->request_mode.get() != RequestMode::GLOBAL)
+ return Step::Status::OK;
+
+ if (!DeleteSkelDirectories(context_->pkgid.get()))
return Status::APP_DIR_ERROR;
- }
+
+ if (!DeleteUserDirectories(context_->pkgid.get()))
+ return Status::APP_DIR_ERROR;
+
return Status::OK;
}
public:
using Step::Step;
+ explicit StepCreateStorageDirectories(InstallerContext* context)
+ : Step(context) {}
+
+ StepCreateStorageDirectories(InstallerContext* context,
+ const std::vector<const char*> additional_shared_dirs)
+ : Step(context),
+ additional_shared_dirs_(std::move(additional_shared_dirs)) {}
+
Status process() override;
Status clean() override { return Status::OK; }
- Status undo() override { return Status::OK; }
+ Status undo() override;
Status precheck() override { return Status::OK; }
+ private:
+ bool CreatePerUserStorageDirectories();
+
+ std::vector<const char*> additional_shared_dirs_;
+
STEP_NAME(CreateStorageDirectories)
};
+++ /dev/null
-// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache-2.0 license that can be
-// found in the LICENSE file.
-
-#include "common/step/filesystem/step_recover_per_user_storage_directories.h"
-#include "common/step/filesystem/step_remove_per_user_storage_directories.h"
-
-namespace bf = boost::filesystem;
-
-namespace common_installer {
-namespace filesystem {
-
-Step::Status StepRecoverPerUserStorageDirectories::RecoveryNew() {
- StepRemovePerUserStorageDirectories step(context_);
- Status status = step.precheck();
- if (status != Status::OK)
- return status;
- return step.process();
-}
-
-} // namespace filesystem
-} // namespace common_installer
-
+++ /dev/null
-// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache-2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef COMMON_STEP_FILESYSTEM_STEP_RECOVER_PER_USER_STORAGE_DIRECTORIES_H_
-#define COMMON_STEP_FILESYSTEM_STEP_RECOVER_PER_USER_STORAGE_DIRECTORIES_H_
-
-#include <manifest_parser/utils/logging.h>
-
-#include "common/installer_context.h"
-#include "common/step/recovery/step_recovery.h"
-
-namespace common_installer {
-namespace filesystem {
-
-/**
- * @brief recovers data and shared directories of application for user
- *
- * This is the part of Recovery Mode that is responsible for restoring data and
- * shared directories for users in case partial install occurs.
- */
-class StepRecoverPerUserStorageDirectories : public recovery::StepRecovery {
- public:
- using StepRecovery::StepRecovery;
-
- Status RecoveryNew() override;
- Status RecoveryUpdate() override { return Status::OK; }
-
- STEP_NAME(RecoverPerUserStorageDirectories)
-};
-
-} // namespace filesystem
-} // namespace common_installer
-
-#endif // COMMON_STEP_FILESYSTEM_STEP_RECOVER_PER_USER_STORAGE_DIRECTORIES_H_
// found in the LICENSE file.
#include "common/step/filesystem/step_recover_storage_directories.h"
+#include "common/step/filesystem/step_remove_per_user_storage_directories.h"
#include <boost/filesystem/path.hpp>
#include <boost/system/error_code.hpp>
namespace common_installer {
namespace filesystem {
+Step::Status StepRecoverStorageDirectories::RecoveryNew() {
+ StepRemovePerUserStorageDirectories step(context_);
+ Status status = step.precheck();
+ if (status != Status::OK)
+ return status;
+ return step.process();
+}
+
bool StepRecoverStorageDirectories::MoveAppStorage(
const bf::path& in_src,
const bf::path& in_dst,
public:
using StepRecovery::StepRecovery;
- Status RecoveryNew() override { return Status::OK; }
+ Status RecoveryNew() override;
Status RecoveryUpdate() override;
Status RecoveryMountUpdate() override;
+++ /dev/null
-// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#include "common/step/filesystem/step_update_per_user_storage_directories.h"
-
-#include <manifest_parser/utils/version_number.h>
-
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-#include <boost/system/error_code.hpp>
-
-#include <string>
-#include <vector>
-
-#include "common/privileges.h"
-
-#include "common/shared_dirs.h"
-#include "common/utils/glist_range.h"
-
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
-
-namespace {
-
-const utils::VersionNumber ver30("3.0");
-const char kSkelAppDir[] = "skel/apps_rw";
-const char kSharedDataDir[] = "shared/data";
-
-common_installer::Step::Status RemoveSharedDir(const std::string& pkgid) {
- bf::path shareddir_path = bf::path(tzplatform_getenv(TZ_SYS_ETC)) /
- bf::path(kSkelAppDir) / pkgid / kSharedDataDir;
- if (!bf::exists(shareddir_path))
- return common_installer::Step::Status::OK;
-
- if (!common_installer::UpdateSkelDirectories(pkgid, true)) {
- LOG(ERROR) << "Failed to remove shared data directory";
- return common_installer::Step::Status::APP_DIR_ERROR;
- }
-
- if (!common_installer::UpdateUserDirectory(pkgid, true)) {
- LOG(ERROR) << "Failed to remove shared data directory";
- return common_installer::Step::Status::APP_DIR_ERROR;
- }
-
- return common_installer::Step::Status::OK;
-}
-
-common_installer::Step::Status CreateSharedDir(const std::string& pkgid) {
- if (!common_installer::UpdateSkelDirectories(pkgid, false)) {
- LOG(ERROR) << "Failed to remove shared data directory";
- return common_installer::Step::Status::APP_DIR_ERROR;
- }
-
- if (!common_installer::UpdateUserDirectory(pkgid, false)) {
- LOG(ERROR) << "Failed to remove shared data directory";
- return common_installer::Step::Status::APP_DIR_ERROR;
- }
-
- return common_installer::Step::Status::OK;
-}
-
-} // namespace
-
-namespace common_installer {
-namespace filesystem {
-
-Step::Status StepUpdatePerUserStorageDirectories::process() {
- if (context_->request_mode.get() != RequestMode::GLOBAL)
- return Step::Status::OK;
-
- manifest_x* manifest = context_->manifest_data.get();
- bf::path path = bf::path(tzplatform_getenv(TZ_SYS_ETC)) /
- bf::path(kSkelAppDir) / context_->pkgid.get() / kSharedDataDir;
- std::string package_id = context_->pkgid.get();
-
- std::string str_ver(manifest->api_version);
- utils::VersionNumber api_version(str_ver);
- if (api_version < ver30) {
- return CreateSharedDir(package_id);
- } else {
- bool shareddata = false;
- for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
- if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
- shareddata = true;
- break;
- }
- }
-
- if (shareddata)
- return CreateSharedDir(package_id);
- else
- return RemoveSharedDir(package_id);
- }
-}
-
-} // namespace filesystem
-} // namespace common_installer
+++ /dev/null
-// Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef COMMON_STEP_FILESYSTEM_STEP_UPDATE_PER_USER_STORAGE_DIRECTORIES_H_
-#define COMMON_STEP_FILESYSTEM_STEP_UPDATE_PER_USER_STORAGE_DIRECTORIES_H_
-
-#include <manifest_parser/utils/logging.h>
-
-#include <vector>
-
-#include "common/step/step.h"
-
-namespace common_installer {
-namespace filesystem {
-
-class StepUpdatePerUserStorageDirectories : public common_installer::Step {
- public:
- using Step::Step;
-
- Status process() override;
- Status clean() override { return Status::OK; }
- Status undo() override {return Status::OK; }
- Status precheck() override { return Status::OK; }
-
- STEP_NAME(UpdatePerUserStorageDirectories)
-};
-
-} // namespace filesystem
-} // namespace common_installer
-
-#endif // COMMON_STEP_FILESYSTEM_STEP_UPDATE_PER_USER_STORAGE_DIRECTORIES_H_
namespace {
const char kSharedData[] = "shared/data";
+const char kSkelApp[] = "skel/apps_rw";
const utils::VersionNumber ver30("3.0");
-common_installer::Step::Status CreateSharedDir(bf::path shareddir_path) {
+bool CreateSharedDir(bf::path shareddir_path) {
if (bf::exists(shareddir_path))
- return common_installer::Step::Status::OK;
+ return true;
if (!common_installer::CreateDir(shareddir_path))
- return common_installer::Step::Status::APP_DIR_ERROR;
+ return false;
- return common_installer::Step::Status::OK;
+ return true;
+}
+
+bool RemovePerUserSharedDir(const std::string& pkgid) {
+ bf::path shareddir_path = bf::path(tzplatform_getenv(TZ_SYS_ETC)) /
+ bf::path(kSkelApp) / pkgid / kSharedData;
+ if (!bf::exists(shareddir_path))
+ return true;
+
+ if (!common_installer::UpdateSkelDirectories(pkgid, true)) {
+ LOG(ERROR) << "Failed to remove shared data directory";
+ return false;
+ }
+
+ if (!common_installer::UpdateUserDirectory(pkgid, true)) {
+ LOG(ERROR) << "Failed to remove shared data directory";
+ return false;
+ }
+
+ return true;
+}
+
+bool CreatePerUserSharedDir(const std::string& pkgid) {
+ if (!common_installer::UpdateSkelDirectories(pkgid, false)) {
+ LOG(ERROR) << "Failed to remove shared data directory";
+ return false;
+ }
+
+ if (!common_installer::UpdateUserDirectory(pkgid, false)) {
+ LOG(ERROR) << "Failed to remove shared data directory";
+ return false;
+ }
+
+ return true;
}
} // namespace
namespace common_installer {
namespace filesystem {
-Step::Status StepUpdateStorageDirectories::process() {
- if (context_->request_mode.get() == RequestMode::GLOBAL)
- return common_installer::Step::Status::OK;
-
+bool StepUpdateStorageDirectories::UpdatePerUserStorageDirectories() {
manifest_x* manifest = context_->manifest_data.get();
+ std::string package_id = context_->pkgid.get();
+ utils::VersionNumber api_version(manifest->api_version);
- if (!manifest) {
- LOG(ERROR) << "Failed to get manifest info";
- return Status::INVALID_VALUE;
+ if (api_version < ver30) {
+ return CreatePerUserSharedDir(package_id);
+ } else {
+ bool shareddata = false;
+ for (auto& priv : GListRange<privilege_x*>(manifest->privileges)) {
+ if (!strcmp(priv->value, privileges::kPrivForSharedData)) {
+ shareddata = true;
+ break;
+ }
+ }
+
+ if (shareddata)
+ return CreatePerUserSharedDir(package_id);
+ else
+ return RemovePerUserSharedDir(package_id);
}
+ return true;
+}
+
+bool StepUpdateStorageDirectories::UpdateStorageDirectories() {
+ manifest_x* manifest = context_->manifest_data.get();
std::string str_ver(manifest->api_version);
utils::VersionNumber api_version(str_ver);
return CreateSharedDir(shared_data_path);
} else {
if (!RemoveAll(shared_data_path))
- return Status::APP_DIR_ERROR;
+ return false;
}
}
+ return true;
+}
+
+Step::Status StepUpdateStorageDirectories::precheck() {
+ if (!context_->manifest_data.get())
+ return Status::INVALID_VALUE;
+ return Status::OK;
+}
+
+Step::Status StepUpdateStorageDirectories::process() {
+ if (context_->request_mode.get() == RequestMode::GLOBAL) {
+ if (!UpdatePerUserStorageDirectories())
+ return Status::APP_DIR_ERROR;
+ } else {
+ if (!UpdateStorageDirectories())
+ return Status::APP_DIR_ERROR;
+ }
return Status::OK;
}
Status process() override;
Status clean() override { return Status::OK; }
Status undo() override { return Status::OK; }
- Status precheck() override { return Status::OK; }
+ Status precheck() override;
STEP_NAME(UpdateStorageDirectories)
+
+ private:
+ bool UpdatePerUserStorageDirectories();
+ bool UpdateStorageDirectories();
};
} // namespace filesystem