PKG_CHECK_MODULES(SQLITE_DEPS REQUIRED sqlite3)
PKG_CHECK_MODULES(SMACK_DEPS REQUIRED libsmack)
-FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem program_options iostreams)
-
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs -pie" )
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
Requires: smack
Requires: cryptsetup
-BuildRequires: boost-devel
BuildRequires: cmake
BuildRequires: gettext-tools
BuildRequires: pkgconfig(glib-2.0)
AUL_DEPS
GLIB_DEPS
BUNDLE_DEPS
- Boost
PKGMGR_DEPS
PKGMGR_INFO_DEPS
PKGMGR_INSTALLER_DEPS
#ifndef FILE_UTIL_HH_
#define FILE_UTIL_HH_
-#include <boost/filesystem.hpp>
-#include <boost/filesystem/path.hpp>
-#include <boost/optional.hpp>
-
-namespace bf = boost::filesystem;
+#include <filesystem>
namespace res_handler {
FSFlag operator|(FSFlag a, FSFlag b);
-bool CreateDir(const boost::filesystem::path& path);
-bool CreateDirs(const std::string& pkgid, const boost::filesystem::path& path);
+bool CreateDir(const std::filesystem::path& path);
+bool CreateDirs(const std::string& pkgid, const std::filesystem::path& path);
-bool CopyDir(const boost::filesystem::path& src,
- const boost::filesystem::path& dst,
+bool CopyDir(const std::filesystem::path& src,
+ const std::filesystem::path& dst,
FSFlag flags = FS_NONE, bool skip_symlink = false);
-bool CopyFile(const boost::filesystem::path& src,
- const boost::filesystem::path& dst);
+bool CopyFile(const std::filesystem::path& src,
+ const std::filesystem::path& dst);
-bool RemoveAll(const boost::filesystem::path& path);
+bool RemoveAll(const std::filesystem::path& path);
-bool SetDirOwnershipAndPermissions(const boost::filesystem::path& path,
+bool SetDirOwnershipAndPermissions(const std::filesystem::path& path,
mode_t mode, uid_t uid, gid_t gid);
-bool SetDirPermissions(const boost::filesystem::path& path,
+bool SetDirPermissions(const std::filesystem::path& path,
mode_t mode);
-bool SetOwnership(const bf::path& path, uid_t uid, gid_t gid);
+bool SetOwnership(const std::filesystem::path& path, uid_t uid, gid_t gid);
} // namespace res_handler
uid_t uid_ = 0;
ReqType req_type_ = ReqType::REQ_TYPE_UNKNOWN;
- void SetRequestType(std::string key);
bool ValidatePkgID();
bool ValidatePathList();
};
#include <pkgmgr-info.h>
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-#include <boost/system/error_code.hpp>
#include <tzplatform_config.h>
+#include <filesystem>
#include <iostream>
#include <list>
#include <string>
+#include <system_error>
#include "include/logging.hh"
#include "include/request_type.hh"
#include "include/res_path_info.hh"
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
namespace {
}
bool CheckFreeSpaceAtPath(int64_t required_size,
- const bf::path& target_location) {
- boost::system::error_code error;
- bf::path root = target_location;
+ const fs::path& target_location) {
+ std::error_code error;
+ fs::path root = target_location;
- while (!bf::exists(root) && root != root.root_path())
+ while (!fs::exists(root) && root != root.root_path())
root = root.parent_path();
- if (!bf::exists(root)) {
+ if (!fs::exists(root)) {
LOG(ERROR) << "No mount point for path: " << target_location;
return false;
}
- bf::space_info space_info = bf::space(root, error);
+ fs::space_info space_info = fs::space(root, error);
if (error) {
LOG(ERROR) << "Failed to get space_info: " << error.message();
return false;
return (space_info.free >= static_cast<uint64_t>(required_size));
}
-int64_t GetBlockSizeForPath(const bf::path& path_in_partition) {
+int64_t GetBlockSizeForPath(const fs::path& path_in_partition) {
struct stat stats;
- if (stat(path_in_partition.string().c_str(), &stats)) {
+ if (stat(path_in_partition.c_str(), &stats)) {
LOG(ERROR) << "stat(" << path_in_partition.string()
<< ") failed - error code: " << errno;
return -1;
return ((size + block_size - 1) / block_size) * block_size;
}
-int64_t GetDirectorySize(const bf::path& path) {
+int64_t GetDirectorySize(const fs::path& path) {
int64_t block_size = GetBlockSizeForPath(path);
if (block_size == -1)
return -1;
int64_t size = 0;
- for (bf::recursive_directory_iterator iter(path);
- iter != bf::recursive_directory_iterator(); ++iter) {
+ for (fs::recursive_directory_iterator iter(path);
+ iter != fs::recursive_directory_iterator(); ++iter) {
struct stat buf;
if (lstat(iter->path().c_str(), &buf) == -1) {
LOG(ERROR) << "lstat() failed for: " << iter->path();
ErrorType ConditionValidator::CheckCopyRequest(
std::list<ResPathInfo> path_list) {
- boost::filesystem::path src_root_path(root_path_);
+ fs::path src_root_path(root_path_);
uintmax_t res_size = 0;
src_root_path = src_root_path / "apps_rw" / pkgid_;
for (auto& path_info : path_list) {
- boost::filesystem::path res_path(src_root_path);
+ fs::path res_path(src_root_path);
res_path = res_path / path_info.GetSrcPath();
- if (!boost::filesystem::exists(res_path)) {
+ if (!fs::exists(res_path)) {
LOG(ERROR) << "Resource not exists : " << res_path;
return ErrorType::ERROR_RES_NOT_FOUND;
}
- if (boost::filesystem::is_directory(res_path))
+ if (fs::is_directory(res_path))
res_size += GetDirectorySize(res_path);
else
- res_size += boost::filesystem::file_size(res_path);
+ res_size += fs::file_size(res_path);
}
LOG(INFO) << "Required size for resource: " << res_size;
ErrorType ConditionValidator::CheckRemoveRequest(
std::list<ResPathInfo> path_list) {
for (auto& path_info : path_list) {
- boost::filesystem::path dst_path(root_path_);
+ fs::path dst_path(root_path_);
dst_path = dst_path / "priv_shared_res"/ pkgid_ / path_info.GetDstPath();
- if (!boost::filesystem::exists(dst_path)) {
+ if (!fs::exists(dst_path)) {
LOG(ERROR) << "Resource not exists : " << dst_path;
return ErrorType::ERROR_RES_NOT_FOUND;
}
#include "include/copy_request_handler.hh"
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-
+#include <filesystem>
#include <iostream>
#include <string>
#include "include/logging.hh"
#include "include/res_path_info.hh"
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
namespace {
AbstractRequestHandler(pkgid, uid, root_path, path_list) {}
ErrorType CopyRequestHandler::Execute() {
- bf::path src_root_path(GetSrcRootPath());
- bf::path dst_root_path(GetDstRootPath());
+ fs::path src_root_path(GetSrcRootPath());
+ fs::path dst_root_path(GetDstRootPath());
if (!CreateDir(dst_root_path))
return ErrorType::ERROR_SYSTEM_ERROR;
for (auto& path_info : GetPathList()) {
- bf::path src_path = src_root_path / path_info.GetSrcPath();
- if (!bf::exists(src_path)) {
+ fs::path src_path = src_root_path / path_info.GetSrcPath();
+ if (!fs::exists(src_path)) {
LOG(ERROR) << "Path not exists :" << src_path;
path_info.SetState(ResPathInfo::State::FAILED);
return ErrorType::ERROR_RES_NOT_FOUND;
}
- bf::path dst_path = dst_root_path / path_info.GetDstPath();
+ fs::path dst_path = dst_root_path / path_info.GetDstPath();
- if (bf::is_directory(src_path)) {
+ if (fs::is_directory(src_path)) {
if (!CopyDir(src_path, dst_path, FS_MERGE_OVERWRITE, true)) {
LOG(ERROR) << "Failed to copy directory " << src_path;
path_info.SetState(ResPathInfo::State::FAILED);
return ErrorType::ERROR_SYSTEM_ERROR;
}
} else {
- if (bf::is_directory(dst_path))
+ if (fs::is_directory(dst_path))
dst_path /= src_path.filename();
if (!CopyFile(src_path, dst_path)) {
}
std::list<ResPathInfo> CopyRequestHandler::GetResultPathList() {
- bf::path src_root_path(GetSrcRootPath());
- bf::path dst_root_path(GetDstRootPath());
+ fs::path src_root_path(GetSrcRootPath());
+ fs::path dst_root_path(GetDstRootPath());
std::list<ResPathInfo> result;
for (const auto& path_info : GetPathList()) {
- bf::path src_path = src_root_path / path_info.GetSrcPath();
- bf::path dst_path = dst_root_path / path_info.GetDstPath();
- bf::path result_path = path_info.GetDstPath();
+ fs::path src_path = src_root_path / path_info.GetSrcPath();
+ fs::path dst_path = dst_root_path / path_info.GetDstPath();
+ fs::path result_path = path_info.GetDstPath();
- if (bf::is_directory(dst_path) && !bf::is_directory(src_path))
+ if (fs::is_directory(dst_path) && !fs::is_directory(src_path))
result_path /= src_path.filename();
result.emplace_back(result_path.string(), "", path_info.GetState());
#include "include/createdir_request_handler.hh"
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-
+#include <filesystem>
#include <iostream>
#include <string>
#include "include/logging.hh"
#include "include/res_path_info.hh"
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
namespace {
AbstractRequestHandler(pkgid, uid, root_path, path_list) {}
ErrorType CreateDirRequestHandler::Execute() {
- bf::path dst_root_path(GetDstRootPath());
+ fs::path dst_root_path(GetDstRootPath());
if (!CreateDir(dst_root_path))
return ErrorType::ERROR_SYSTEM_ERROR;
for (auto& path_info : GetPathList()) {
- bf::path dst_path = dst_root_path / path_info.GetSrcPath();
+ fs::path dst_path = dst_root_path / path_info.GetSrcPath();
if (!CreateDirs(GetPkgID(), dst_path)) {
path_info.SetState(ResPathInfo::State::FAILED);
return ErrorType::ERROR_SYSTEM_ERROR;
#include <sys/stat.h>
#include <sys/types.h>
#include <pwd.h>
+#include <unistd.h>
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-#include <boost/optional.hpp>
-#include <boost/system/error_code.hpp>
+#include <algorithm>
+#include <filesystem>
+#include <string>
+#include <random>
#include "include/logging.hh"
-namespace bs = boost::system;
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
namespace {
constexpr mode_t kDefaultMode640 = S_IRUSR | S_IWUSR | S_IRGRP;
constexpr mode_t kDirectoryMode650 = S_IRUSR | S_IWUSR | S_IRGRP | S_IXGRP;
+// To replace with std::filesystem::unique_path()
+fs::path GenerateUniquePath(const std::string& format) {
+ static constexpr auto chars =
+ "0123456789"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz";
+ std::random_device rd;
+ std::mt19937 gen(rd());
+ auto dist = std::uniform_int_distribution{{}, std::strlen(chars) - 1};
+ size_t len = std::count_if(format.begin(), format.end(),
+ [](char c) { return c == '%'; });
+
+ auto random_string = std::string(len, '\0');
+ std::generate_n(begin(random_string), len,
+ [&]() {
+ return chars[dist(gen)];
+ });
+
+ auto iter = random_string.begin();
+ std::string result(format);
+ std::transform(result.begin(), result.end(), result.begin(),
+ [&](char c) {
+ return c == '%' ? *iter++ : c;
+ });
+
+ return result;
+}
+
} // namespace
namespace res_handler {
return static_cast<FSFlag>(static_cast<int>(a) | static_cast<int>(b));
}
-bool SetDirPermissions(const boost::filesystem::path& path,
+bool SetDirPermissions(const fs::path& path,
mode_t mode) {
- if (chmod(path.string().c_str(), mode) != 0) {
+ if (chmod(path.c_str(), mode) != 0) {
LOG(ERROR) << "Failed to set permissions for path: " << path
<< ", errno : " << errno;
return false;
return true;
}
-bool RemoveAll(const bf::path& path) {
- if (!exists(path) && !bf::is_symlink(bf::symlink_status(path)))
+bool RemoveAll(const fs::path& path) {
+ if (!exists(path) && !fs::is_symlink(fs::symlink_status(path)))
return true;
- bs::error_code error;
- bf::remove_all(path, error);
+ std::error_code error;
+ fs::remove_all(path, error);
if (error) {
LOG(ERROR) << "Cannot remove: " << path << ", " << error.message();
return true;
}
-bool CopyDir(const boost::filesystem::path& src,
- const boost::filesystem::path& dst,
+bool CopyDir(const fs::path& src,
+ const fs::path& dst,
FSFlag flags, bool skip_symlink) {
try {
// Check whether the function call is valid
- if (!bf::exists(src) || !bf::is_directory(src)) {
+ if (!fs::exists(src) || !fs::is_directory(src)) {
LOG(ERROR) << "Source directory " << src
<< " does not exist or is not a directory.";
return false;
}
- if (!bf::exists(dst)) {
+ if (!fs::exists(dst)) {
// Create the destination directory
if (!CreateDir(dst)) {
LOG(ERROR) << "Unable to create destination directory" << dst;
return false;
}
}
- } catch (const bf::filesystem_error& error) {
+ } catch (const fs::filesystem_error& error) {
LOG(ERROR) << "Failed to copy directory: " << error.what();
return false;
}
// Iterate through the source directory
- for (bf::directory_iterator file(src);
- file != bf::directory_iterator();
+ for (fs::directory_iterator file(src);
+ file != fs::directory_iterator();
++file) {
try {
- bf::path current(file->path());
- bf::path target = dst / current.filename();
+ fs::path current(file->path());
+ fs::path target = dst / current.filename();
- if (bf::is_symlink(symlink_status(current))) {
+ if (fs::is_symlink(symlink_status(current))) {
if (skip_symlink)
continue;
if ((flags & (FS_MERGE_SKIP | FS_MERGE_OVERWRITE)) &&
- bf::exists(target))
+ fs::exists(target))
continue;
- bs::error_code error;
- bf::copy_symlink(current, target, error);
+ std::error_code error;
+ fs::copy_symlink(current, target, error);
if (error) {
LOG(ERROR) << "Failed to copy symlink: " << current << ", "
<< error.message();
return false;
}
- } else if (bf::is_directory(current)) {
+ } else if (fs::is_directory(current)) {
// Found directory: Recursion
if (!CopyDir(current, target, flags, skip_symlink)) {
return false;
}
} else {
- if ((flags & FS_MERGE_SKIP) && bf::exists(target))
+ if ((flags & FS_MERGE_SKIP) && fs::exists(target))
continue;
- bf::path destination = target;
+ fs::path destination = target;
if (flags & FS_COMMIT_COPY_FILE)
destination =
- bf::unique_path(target.parent_path() / "%%%%-%%%%-%%%%-%%%%");
+ target.parent_path() / GenerateUniquePath("%%%%-%%%%-%%%%-%%%%");
if (flags & FS_MERGE_OVERWRITE)
- bf::copy_file(current, destination,
- bf::copy_option::overwrite_if_exists);
+ fs::copy_file(current, destination,
+ fs::copy_options::overwrite_existing);
else
- bf::copy_file(current, destination);
+ fs::copy_file(current, destination);
if (flags & FS_COMMIT_COPY_FILE) {
if (flags & FS_MERGE_OVERWRITE)
- bf::remove(target);
+ fs::remove(target);
- bf::rename(destination, target);
+ fs::rename(destination, target);
}
if (!SetDirOwnershipAndPermissions(
destination, kDirectoryMode650, kRootUID, kPrivPlatformGid))
return false;
}
- } catch (const bf::filesystem_error& error) {
+ } catch (const fs::filesystem_error& error) {
LOG(ERROR) << "Failed to copy directory: " << error.what();
return false;
}
return true;
}
-bool CreateDir(const bf::path& path) {
- if (bf::exists(path))
+bool CreateDir(const fs::path& path) {
+ if (fs::exists(path))
return true;
- boost::system::error_code error;
- bf::create_directory(path, error);
+ std::error_code error;
+ fs::create_directory(path, error);
if (error) {
LOG(ERROR) << "Failed to create directory: "
- << boost::system::system_error(error).what();
+ << std::system_error(error).what();
return false;
}
return true;
}
-bool CopyFile(const bf::path& src, const bf::path& dst) {
- if (bf::is_symlink(bf::symlink_status(src)))
+bool CopyFile(const fs::path& src, const fs::path& dst) {
+ if (fs::is_symlink(fs::symlink_status(src)))
return true;
- bs::error_code error;
- bf::copy_file(src, dst, bf::copy_option::overwrite_if_exists, error);
+ std::error_code error;
+ fs::copy_file(src, dst, fs::copy_options::overwrite_existing, error);
if (error) {
LOG(WARNING) << "copy file " << src << " due to error ["
<< error.message() << "]";
return true;
}
-bool SetOwnership(const bf::path& path, uid_t uid, gid_t gid) {
+bool SetOwnership(const fs::path& path, uid_t uid, gid_t gid) {
int ret = lchown(path.c_str(), uid, gid);
if (ret != 0) {
LOG(ERROR) << "Failed to change owner of: " << path;
return true;
}
-bool SetDirOwnershipAndPermissions(const boost::filesystem::path& path,
+bool SetDirOwnershipAndPermissions(const fs::path& path,
mode_t mode, uid_t uid, gid_t gid) {
if (!SetOwnership(path, uid, gid)) {
LOG(ERROR) << "Failed to change owner: " << path
}
bool CreateDirs(
- const std::string& pkgid, const boost::filesystem::path& path) {
- boost::system::error_code error;
- bf::create_directories(path, error);
+ const std::string& pkgid, const fs::path& path) {
+ std::error_code error;
+ fs::create_directories(path, error);
if (error) {
LOG(ERROR) << "Failed to create directory: "
- << boost::system::system_error(error).what();
+ << std::system_error(error).what();
return false;
}
- bf::path target_path = path;
+ fs::path target_path = path;
while(target_path.filename() != pkgid) {
if (!SetDirOwnershipAndPermissions(
#include "include/param_checker.hh"
+#include <getopt.h>
#include <pkgmgr-info.h>
-
-#include <boost/exception/diagnostic_information.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-#include <boost/program_options.hpp>
-#include <boost/system/error_code.hpp>
+#include <unistd.h>
#include <string>
#include <iostream>
#include "include/request_type.hh"
#include "include/res_path_info.hh"
-namespace bs = boost::system;
-namespace bpo = boost::program_options;
-
namespace {
bool IsPathTraversal(const std::string& path) {
return true;
}
+const struct option long_opts[] = {
+ { "uid", required_argument, nullptr, 'u' },
+ { "session-id", required_argument, nullptr, 'k' },
+ { "path", required_argument, nullptr, 'p' },
+ { "remove", required_argument, nullptr, 'r' },
+ { "delete", required_argument, nullptr, 'd' },
+ { "copy", required_argument, nullptr, 'c' },
+ { "createdir", required_argument, nullptr, 'D' },
+ { "help", no_argument, nullptr, 'h' },
+};
+
+const char kHelpMessage[] = R"(
+ -u [ --uid ] arg (=0) user id
+ -k [ --session-id ] arg session id
+ -p [ --path ] arg source-destination path
+ -r [ --remove ] arg remove shared resource
+ -d [ --delete ] arg delete shared resource for package
+ -c [ --copy ] arg copy resource
+ -D [ --createdir ] arg create directories
+ -h [ --help ] Show this message
+)";
+
+void PrintHelp() {
+ std::cerr << kHelpMessage;
+}
+
} // namespace
namespace res_handler {
ParamChecker::ParamChecker(int argc, char* argv[]) {
- bpo::options_description options;
-
- options.add_options()
- ("uid,u", bpo::value<int>()->default_value(0), "user id")
- ("session-id,k", bpo::value<std::string>()->default_value(""),
- "session id")
- ("path,p", bpo::value<std::vector<std::string>>()->multitoken(),
- "source-destination path")
- ("remove,r", bpo::value<std::string>(), "remove shared resource")
- ("delete,d", bpo::value<std::string>(),
- "delete shared resource for package")
- ("copy,c", bpo::value<std::string>(), "copy resource")
- ("createdir,D", bpo::value<std::string>(), "create directories")
- ("help,h", "Show this message");
-
- bpo::parsed_options parsed_options = bpo::command_line_parser(argc, argv)
- .options(options)
- .run();
-
- for (const bpo::option& o : parsed_options.options) {
- if (o.string_key == "uid") {
- uid_ = static_cast<uid_t>(std::stoi(o.value.front()));
- } else if (o.string_key == "session-id") {
- session_id_ = o.value.front();
- } else if (o.string_key == "path") {
- if (o.value.front() == o.value.back())
- path_info_list_.emplace_back(o.value.front(), "");
- else
- path_info_list_.emplace_back(o.value.front(), o.value.back());
- } else if (o.string_key == "copy" ||
- o.string_key == "delete" ||
- o.string_key == "remove" ||
- o.string_key == "createdir") {
- pkgid_ = o.value.front();
- SetRequestType(o.string_key);
- } else if (o.string_key == "help") {
- std::cout << options;
- } else {
- std::cout << "Invalid option : " << o.string_key << std::endl;
+ // force reset global variable for getopt_long() before parsing
+ optind = 1;
+ int opt_idx;
+ while (true) {
+ int opt = getopt_long(argc, argv, "u:k:p:r:d:c:D:h", long_opts, &opt_idx);
+ if (opt == -1)
+ break;
+
+ switch (opt) {
+ case 'u':
+ if (optarg)
+ uid_ = std::stoi(optarg);
+ break;
+ case 'k':
+ if (optarg)
+ session_id_ = optarg;
+ break;
+ case 'p':
+ if (optarg) {
+ std::string src = optarg;
+ std::string dst;
+ if ((optind + 1) <= argc && *argv[optind] != '-')
+ dst = argv[optind];
+ path_info_list_.emplace_back(src, dst);
+ }
+ break;
+ case 'r':
+ if (optarg)
+ pkgid_ = optarg;
+ req_type_ = ReqType::REQ_TYPE_REMOVE;
+ break;
+ case 'd':
+ if (optarg)
+ pkgid_ = optarg;
+ req_type_ = ReqType::REQ_TYPE_UNINSTALL;
+ break;
+ case 'c':
+ if (optarg)
+ pkgid_ = optarg;
+ req_type_ = ReqType::REQ_TYPE_NEW;
+ break;
+ case 'D':
+ if (optarg)
+ pkgid_ = optarg;
+ req_type_ = ReqType::REQ_TYPE_CREATEDIR;
+ break;
+ case 'h':
+ PrintHelp();
+ break;
+ default:
+ std::cout << "Invalid option" << std::endl;
+ PrintHelp();
+ break;
}
}
}
return true;
}
-void ParamChecker::SetRequestType(std::string key) {
- if (key == "copy")
- req_type_ = ReqType::REQ_TYPE_NEW;
- else if (key == "remove")
- req_type_ = ReqType::REQ_TYPE_REMOVE;
- else if (key == "delete")
- req_type_ = ReqType::REQ_TYPE_UNINSTALL;
- else if (key == "createdir")
- req_type_ = ReqType::REQ_TYPE_CREATEDIR;
-}
-
bool ParamChecker::ValidatePkgID() {
if (pkgid_.size() == 0) {
LOG(ERROR) << "pkgid is empty";
#include "include/remove_request_handler.hh"
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-
+#include <filesystem>
#include <iostream>
#include <string>
#include "include/logging.hh"
#include "include/res_path_info.hh"
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
namespace {
AbstractRequestHandler(pkgid, uid, root_path, path_list) {}
ErrorType RemoveRequestHandler::Execute() {
- bf::path dst_root_path(GetDstRootPath());
+ fs::path dst_root_path(GetDstRootPath());
- if (!bf::exists(dst_root_path)) {
+ if (!fs::exists(dst_root_path)) {
LOG(ERROR) << "root path not exists";
return ErrorType::ERROR_RES_NOT_FOUND;
}
for (auto& path_info : GetPathList()) {
- bf::path dst_path = dst_root_path / path_info.GetSrcPath();
- if (!bf::exists(dst_path)) {
+ fs::path dst_path = dst_root_path / path_info.GetSrcPath();
+ if (!fs::exists(dst_path)) {
LOG(ERROR) << "Path not exists: " << dst_path;
continue;
}
#include "include/uninstall_request_handler.hh"
+#include <filesystem>
#include <iostream>
#include <string>
#include "include/logging.hh"
#include "include/res_path_info.hh"
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
namespace {
return ErrorType::ERROR_INVALID_PARAMETER;
}
- bf::path root_path(GetDstRootPath());
- if (!bf::exists(root_path)) {
+ fs::path root_path(GetDstRootPath());
+ if (!fs::exists(root_path)) {
LOG(WARNING) << "path not exists : " << root_path;
return ErrorType::ERROR_NONE;
}
SMACK_DEPS
SQLITE_DEPS
TZPLATFORM_DEPS
- Boost
)
INSTALL(TARGETS ${TARGET_PKGMGR_TOOL_UNITTESTS} DESTINATION /usr/bin/)
#include <gtest/gtest.h>
#include <stdio.h>
-#include <boost/filesystem/fstream.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-#include <boost/system/error_code.hpp>
-
+#include <filesystem>
#include <list>
#include <memory>
#include <string>
using res_handler::ResPathInfo;
using res_handler::UninstallRequestHandler;
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
+namespace fs = std::filesystem;
namespace {
return "./tests/unit_tests/res-copy/data";
}
-bf::path GetSrcRootPath() {
- return bf::path(GetRootPath()) / "apps_rw" / kTestPkgID;
+fs::path GetSrcRootPath() {
+ return fs::path(GetRootPath()) / "apps_rw" / kTestPkgID;
}
-bf::path GetDstRootPath() {
- return bf::path(GetRootPath()) / "priv_shared_res" / kTestPkgID;
+fs::path GetDstRootPath() {
+ return fs::path(GetRootPath()) / "priv_shared_res" / kTestPkgID;
}
} // namespace
virtual ~CopyRequestHandlerTest() {}
virtual void SetUp() {
- bf::create_directories(GetDstRootPath() / "dest_dir");
+ fs::create_directories(GetDstRootPath() / "dest_dir");
EXPECT_CALL(GetMock<OsMock>(), lchown(_, _, _)).WillRepeatedly(Return(0));
EXPECT_CALL(GetMock<OsMock>(), chmod(_, _)).WillRepeatedly(Return(0));
}
virtual void TearDown() {
- bf::remove_all(GetDstRootPath());
+ fs::remove_all(GetDstRootPath());
}
};
virtual ~RemoveRequestHandlerTest() {}
virtual void SetUp() {
- bf::create_directories(GetDstRootPath() / "new_dir/new_dir2");
- bf::copy_file(GetSrcRootPath() / "data/resource_file.txt",
+ fs::create_directories(GetDstRootPath() / "new_dir/new_dir2");
+ fs::copy_file(GetSrcRootPath() / "data/resource_file.txt",
GetDstRootPath() / "resource_file.txt");
- bf::copy_file(GetSrcRootPath() / "data/resource_file.txt",
+ fs::copy_file(GetSrcRootPath() / "data/resource_file.txt",
GetDstRootPath() / "new_dir/resource_file.txt");
- bf::copy_file(GetSrcRootPath() / "data/resource_file.txt",
+ fs::copy_file(GetSrcRootPath() / "data/resource_file.txt",
GetDstRootPath() / "new_dir/new_dir2/resource_file.txt");
}
virtual void TearDown() {
- bf::remove_all(GetDstRootPath());
+ fs::remove_all(GetDstRootPath());
}
};
virtual ~UninstallRequestHandlerTest() {}
virtual void SetUp() {
- bf::create_directories(GetDstRootPath());
+ fs::create_directories(GetDstRootPath());
}
virtual void TearDown() {
- bf::remove_all(GetDstRootPath());
+ fs::remove_all(GetDstRootPath());
}
};
virtual ~CreateDirRequestHandlerTest() {}
virtual void SetUp() {
- bf::create_directories(GetDstRootPath() / "existed_dir");
+ fs::create_directories(GetDstRootPath() / "existed_dir");
}
virtual void TearDown() {
- bf::remove_all(GetDstRootPath());
+ fs::remove_all(GetDstRootPath());
}
};
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyFileAtRootToRoot_ChangeFileName) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "another_name.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyFileAtRootToDirectory) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "dest_dir";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyFileAtRootToDirectory_ChangeFileName) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "dest_dir";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "newname.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyFileAtDirectoryToRoot) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file3.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyFileAtDirectoryToRoot_ChangeFileName) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "newname.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyFileAtDirectoryToDirectory) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "dest_dir";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file3.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToRoot_ChangeFileName) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "dest_dir";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "newname.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToRoot) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file3.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path = check_path.parent_path();
check_path /= "resource_dir2";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file2.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToDirectory) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "dest_dir";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file3.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path = check_path.parent_path();
check_path /= "resource_dir2";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file2.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToDirectory2) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_dir1";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file3.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path = check_path.parent_path();
check_path /= "resource_dir2";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file2.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtDirectoryToRoot) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file2.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtDirectoryToDirectory) {
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path = GetDstRootPath();
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path = GetDstRootPath();
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "dest_dir";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "resource_file2.txt";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CopyRequestHandlerTest, ResNotexists) {
RemoveRequestHandler handler("test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(GetDstRootPath() / "resource_file.txt");
- EXPECT_FALSE(bf::exists(check_path));
+ fs::path check_path(GetDstRootPath() / "resource_file.txt");
+ EXPECT_FALSE(fs::exists(check_path));
}
TEST_F(RemoveRequestHandlerTest, RemoveFileAtDirectory) {
RemoveRequestHandler handler("test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(GetDstRootPath() / "new_dir/resource_file.txt");
- EXPECT_FALSE(bf::exists(check_path));
+ fs::path check_path(GetDstRootPath() / "new_dir/resource_file.txt");
+ EXPECT_FALSE(fs::exists(check_path));
}
TEST_F(RemoveRequestHandlerTest, RemoveDirectoryAtRoot) {
RemoveRequestHandler handler("test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(GetDstRootPath() / "new_dir");
- EXPECT_FALSE(bf::exists(check_path));
+ fs::path check_path(GetDstRootPath() / "new_dir");
+ EXPECT_FALSE(fs::exists(check_path));
}
TEST_F(RemoveRequestHandlerTest, RemoveDirectoryAtDirectory) {
RemoveRequestHandler handler("test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(GetDstRootPath() / "new_dir/new_dir2");
- EXPECT_FALSE(bf::exists(check_path));
+ fs::path check_path(GetDstRootPath() / "new_dir/new_dir2");
+ EXPECT_FALSE(fs::exists(check_path));
}
TEST_F(UninstallRequestHandlerTest, RemoveRootPath) {
UninstallRequestHandler handler(
"test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- EXPECT_FALSE(bf::exists(GetDstRootPath()));
+ EXPECT_FALSE(fs::exists(GetDstRootPath()));
}
TEST_F(UninstallRequestHandlerTest, RootNotExists) {
std::list<ResPathInfo> path_list;
- bf::remove_all(GetDstRootPath());
+ fs::remove_all(GetDstRootPath());
UninstallRequestHandler handler(
"test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(),
res_handler::ErrorType::ERROR_NONE);
- EXPECT_TRUE(bf::exists(GetDstRootPath() / "new_dir"));
+ EXPECT_TRUE(fs::exists(GetDstRootPath() / "new_dir"));
}
TEST_F(CreateDirRequestHandlerTest, CreateOneAtExistedDirectory) {
EXPECT_EQ(handler.Execute(),
res_handler::ErrorType::ERROR_NONE);
- EXPECT_TRUE(bf::exists(GetDstRootPath() / "existed_dir/new_dir"));
+ EXPECT_TRUE(fs::exists(GetDstRootPath() / "existed_dir/new_dir"));
}
TEST_F(CreateDirRequestHandlerTest, CreateHierachyAtRoot) {
EXPECT_EQ(handler.Execute(),
res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(GetDstRootPath() / "new_dir");
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path(GetDstRootPath() / "new_dir");
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "another_new_dir";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}
TEST_F(CreateDirRequestHandlerTest, CreateHierachyAtExistedDirectory) {
EXPECT_EQ(handler.Execute(),
res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(GetDstRootPath() / "existed_dir/new_dir");
- EXPECT_TRUE(bf::exists(check_path));
+ fs::path check_path(GetDstRootPath() / "existed_dir/new_dir");
+ EXPECT_TRUE(fs::exists(check_path));
check_path /= "another_new_dir";
- EXPECT_TRUE(bf::exists(check_path));
+ EXPECT_TRUE(fs::exists(check_path));
}