<< install_path.parent_path().string();
return Step::Status::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.get()),
- install_path)) {
- 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.get(), error);
- if (error) {
- LOG(WARNING) << "Cannot remove temporary directory: "
- << context_->unpacked_dir_path.get();
- }
+ if (!utils::MoveDir(context_->unpacked_dir_path.get(), install_path)) {
+ LOG(ERROR) << "Cannot move widget directory to install path";
+ return Status::ERROR;
}
- LOG(INFO) << "Successfully move/copy: " << context_->unpacked_dir_path.get()
- << " to: " << install_path.string() << " directory";
+
+ LOG(INFO) << "Successfully move: " << context_->unpacked_dir_path.get()
+ << " to: " << install_path << " directory";
return Status::OK;
}
#include "utils/file_util.h"
#include <boost/filesystem/path.hpp>
+#include <boost/system/error_code.hpp>
#include <string>
#include "utils/logging.h"
namespace common_installer {
namespace utils {
+namespace bs = boost::system;
namespace fs = boost::filesystem;
bool CreateDir(const fs::path& path) {
return true;
}
+bool MoveDir(const fs::path& src, const fs::path& dst) {
+ if (fs::exists(dst))
+ return false;
+ bs::error_code error;
+ fs::rename(src, dst, error);
+ if (error) {
+ LOG(WARNING) << "Cannot move directory: " << src << ". Will copy/remove...";
+ if (!utils::CopyDir(src, dst)) {
+ LOG(ERROR) << "Cannot copy directory: " << src;
+ return false;
+ }
+ fs::remove_all(src, error);
+ if (error) {
+ LOG(ERROR) << "Cannot remove old directory when coping: " << src;
+ return false;
+ }
+ }
+ return true;
+}
+
+bool MoveFile(const fs::path& src, const fs::path& dst) {
+ if (fs::exists(dst))
+ return false;
+ bs::error_code error;
+ fs::rename(src, dst, error);
+ if (error) {
+ LOG(WARNING) << "Cannot move file: " << src << ". Will copy/remove...";
+ fs::copy_file(src, dst, fs::copy_option::overwrite_if_exists, error);
+ if (error) {
+ return false;
+ }
+ fs::remove_all(src, error);
+ if (error) {
+ LOG(ERROR) << "Cannot remove old file when coping: " << src;
+ }
+ }
+ return true;
+}
+
} // namespace utils
} // namespace common_installer
bool CopyDir(const boost::filesystem::path& src,
const boost::filesystem::path& dst);
+bool MoveDir(const boost::filesystem::path& src,
+ const boost::filesystem::path& dst);
+
+bool MoveFile(const boost::filesystem::path& src,
+ const boost::filesystem::path& dst);
+
} // namespace utils
} // namespace common_installer