#include "common/step/step_remove_files.h"
+#include <boost/filesystem/operations.hpp>
#include <boost/system/error_code.hpp>
-#include "common/backup_paths.h"
-#include "common/utils/file_util.h"
+namespace bs = boost::system;
+namespace bf = boost::filesystem;
namespace common_installer {
namespace filesystem {
-namespace bs = boost::system;
-namespace bf = boost::filesystem;
-
Step::Status StepRemoveFiles::precheck() {
if (!context_->manifest_data.get()) {
LOG(ERROR) << "manifest_data attribute is empty";
}
Step::Status StepRemoveFiles::process() {
- bf::path backup_path = GetBackupPathForPackagePath(context_->pkg_path.get());
- if (!MoveDir(context_->pkg_path.get(), backup_path)) {
- LOG(ERROR) << "Cannot remove widget files from its location";
- }
- LOG(DEBUG) << "Removed directory: " << context_->pkg_path.get();
- return Status::OK;
-}
-
-Step::Status StepRemoveFiles::clean() {
bs::error_code error;
- bf::path backup_path = GetBackupPathForPackagePath(context_->pkg_path.get());
- bf::remove_all(backup_path, error);
- return Status::OK;
-}
+ bf::path pkg_path(context_->pkg_path.get());
+ bf::remove_all(pkg_path, error);
-Step::Status StepRemoveFiles::undo() {
- bf::path backup_path = GetBackupPathForPackagePath(context_->pkg_path.get());
- if (bf::exists(backup_path)) {
- LOG(DEBUG) << "Restoring directory: " << context_->pkg_path.get();
- if (!MoveDir(backup_path, context_->pkg_path.get())) {
- LOG(ERROR) << "Cannot restore widget files";
- return Status::APP_DIR_ERROR;
- }
+ if (error) {
+ LOG(ERROR) << "Can't remove directory:" << context_->pkg_path.get().c_str();
+ } else {
+ LOG(DEBUG) << "Removed directory: " << context_->pkg_path.get();
}
-
return Status::OK;
}
using Step::Step;
Status process() override;
- Status clean() override;
- Status undo() override;
+ Status clean() override { return Status::OK; }
+ Status undo() override { return Status::OK; }
Status precheck() override;
SCOPE_LOG_TAG(Remove)
#include "common/step/step_remove_icons.h"
+#include <boost/filesystem/operations.hpp>
#include <boost/system/error_code.hpp>
#include <pkgmgr-info.h>
#include <cstring>
#include <string>
-#include "common/backup_paths.h"
-#include "common/utils/file_util.h"
#include "common/utils/glist_range.h"
-namespace common_installer {
-namespace filesystem {
-
namespace bs = boost::system;
namespace bf = boost::filesystem;
+namespace common_installer {
+namespace filesystem {
+
Step::Status StepRemoveIcons::precheck() {
if (!context_->manifest_data.get()) {
LOG(ERROR) << "manifest_data attribute is empty";
iter != bf::directory_iterator(); ++iter) {
if (!bf::is_regular_file(iter->path()))
continue;
+ bs::error_code error;
for (application_x* app :
GListRange<application_x*>(
context_->manifest_data.get()->application)) {
if (app->icon) {
std::string filename = iter->path().filename().string();
if (filename.find(app->appid) == 0) {
- bf::path icon_backup = GetBackupPathForIconFile(iter->path());
- backups_.emplace_back(iter->path(), icon_backup);
+ bf::remove(iter->path(), error);
+ if (error) {
+ LOG(WARNING) << "Failed to remove: " << filename;
+ }
}
}
}
return Status::OK;
}
-Step::Status StepRemoveIcons::clean() {
- bs::error_code error;
- if (!backups_.empty()) {
- LOG(DEBUG) << "Clean up icons files...";
- for (auto& pair : backups_) {
- bf::remove(pair.first, error);
- if (error) {
- LOG(WARNING) << "Failed to remove: " << pair.first;
- }
- }
- }
- return Status::OK;
-}
-
-Step::Status StepRemoveIcons::undo() {
- Step::Status ret = Status::OK;
- if (!backups_.empty()) {
- LOG(DEBUG) << "Restoring icons files...";
- for (auto& pair : backups_) {
- if (!MoveFile(pair.first, pair.second)) {
- LOG(ERROR) << "Failed to restore: " << pair.second;
- // We need to try to restore all icons anyway...
- ret = Status::ICON_ERROR;
- }
- }
- }
- return ret;
-}
} // namespace filesystem
} // namespace common_installer
using Step::Step;
Status process() override;
- Status clean() override;
- Status undo() override;
+ Status clean() override { return Status::OK; }
+ Status undo() override { return Status::OK; }
Status precheck() override;
- private:
- std::vector<std::pair<boost::filesystem::path, boost::filesystem::path>>
- backups_;
-
SCOPE_LOG_TAG(RemoveIcons)
};