Implement CreateDir request handler which responsible for creating new directories.
Change-Id: Ib5dba75b3f2d8975917eeb248fcd7cdf15afad95
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
class AbstractRequestHandler {
public:
AbstractRequestHandler(
- std::string pkgid, std::string root_path, std::list<ResPathInfo> path_list) :
- pkgid_(pkgid), root_path_(root_path), path_list_(path_list) {};
+ std::string pkgid, uid_t uid,
+ std::string root_path, std::list<ResPathInfo> path_list)
+ : pkgid_(pkgid), uid_(uid), root_path_(root_path),
+ path_list_(path_list) {};
virtual ErrorType Execute() = 0;
virtual const std::string GetRequestHandlerType() const = 0;
std::string GetRootPath();
const std::string GetPkgID() const;
const std::list<ResPathInfo> GetPathList() const;
+ uid_t GetUID() const;
private:
std::string pkgid_;
+ uid_t uid_;
std::string root_path_;
std::list<ResPathInfo> path_list_;
};
class CopyRequestHandler : public AbstractRequestHandler {
public:
- CopyRequestHandler(std::string pkgid, std::string root_path,
+ CopyRequestHandler(std::string pkgid, uid_t uid, std::string root_path,
std::list<ResPathInfo> path_list);
ErrorType Execute() override;
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CREATEDIR_REQUEST_HANDLER_HH_
+#define CREATEDIR_REQUEST_HANDLER_HH_
+
+#include <list>
+#include <string>
+
+#include "include/abstract_request_handler.hh"
+#include "include/error_type.hh"
+#include "include/res_path_info.hh"
+
+namespace res_handler {
+
+class CreateDirRequestHandler : public AbstractRequestHandler {
+ public:
+ CreateDirRequestHandler(std::string pkgid, uid_t uid, std::string root_path,
+ std::list<ResPathInfo> path_list);
+
+ ErrorType Execute() override;
+ const std::string GetRequestHandlerType() const override;
+};
+
+} // namespace res_handler
+
+#endif // CREATEDIR_REQUEST_HANDLER_HH_
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
+#include <boost/optional.hpp>
+
+namespace bf = boost::filesystem;
namespace res_handler {
FSFlag operator|(FSFlag a, FSFlag b);
-bool CreateDir(const boost::filesystem::path& path);
+bool CreateDir(const boost::filesystem::path& path, uid_t uid = 0);
+bool CreateDirs(const std::string& pkgid, const boost::filesystem::path& path, uid_t uid = 0);
bool CopyDir(const boost::filesystem::path& src,
const boost::filesystem::path& dst,
- FSFlag flags = FS_NONE, bool skip_symlink = false);
+ uid_t uid, FSFlag flags = FS_NONE, bool skip_symlink = false);
bool CopyFile(const boost::filesystem::path& src,
const boost::filesystem::path& dst);
bool RemoveAll(const boost::filesystem::path& path);
+boost::optional<gid_t> GetGidByUid(uid_t uid);
+
+bool SetDirOwnershipAndPermissions(const boost::filesystem::path& path,
+ boost::filesystem::perms permissions, uid_t uid,
+ gid_t gid);
+
+bool SetDirPermissions(const boost::filesystem::path& path,
+ boost::filesystem::perms permissions);
+
+bool SetOwnership(const bf::path& path, uid_t uid, gid_t gid);
+
} // namespace res_handler
#endif // FILE_UTIL_HH_
class RemoveRequestHandler : public AbstractRequestHandler {
public:
RemoveRequestHandler(
- std::string pkgid, std::string root_path,
+ std::string pkgid, uid_t uid, std::string root_path,
std::list<ResPathInfo> path_list);
ErrorType Execute() override;
REQ_TYPE_NEW = 0,
REQ_TYPE_REMOVE = 1,
REQ_TYPE_UNINSTALL,
+ REQ_TYPE_CREATEDIR,
REQ_TYPE_UNKNOWN
};
class UninstallRequestHandler : public AbstractRequestHandler {
public:
UninstallRequestHandler(
- std::string pkgid, std::string root_path, std::list<ResPathInfo> path_list);
+ std::string pkgid, uid_t uid,
+ std::string root_path, std::list<ResPathInfo> path_list);
ErrorType Execute() override;
const std::string GetRequestHandlerType() const override;
return path_list_;
}
+uid_t AbstractRequestHandler::GetUID() const {
+ return uid_;
+}
+
} // namespace res_handler
namespace res_handler {
CopyRequestHandler::CopyRequestHandler(
- std::string pkgid, std::string root_path,
+ std::string pkgid, uid_t uid, std::string root_path,
std::list<ResPathInfo> path_list) :
- AbstractRequestHandler(pkgid, root_path, path_list) {}
+ AbstractRequestHandler(pkgid, uid, root_path, path_list) {}
ErrorType CopyRequestHandler::Execute() {
bf::path root_path(GetRootPath());
bf::path src_root_path = root_path / "apps_rw" / GetPkgID();
bf::path dst_root_path = root_path / "shared_res" / GetPkgID();
- if (!CreateDir(dst_root_path))
+ if (!CreateDir(dst_root_path, GetUID()))
return ErrorType::ERROR_SYSTEM_ERROR;
for (auto& path_info : GetPathList()) {
bf::path dst_path = dst_root_path / path_info.GetDstPath();
if (bf::is_directory(src_path)) {
- if (!CopyDir(src_path, dst_path,
+ if (!CopyDir(src_path, dst_path, GetUID(),
FS_MERGE_OVERWRITE | FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS, true)) {
LOG(ERROR) << "Failed to copy directory " << src_path;
return ErrorType::ERROR_SYSTEM_ERROR;
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/createdir_request_handler.hh"
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+
+#include <iostream>
+#include <string>
+
+#include "include/abstract_request_handler.hh"
+#include "include/error_type.hh"
+#include "include/file_util.hh"
+#include "include/logging.hh"
+#include "include/res_path_info.hh"
+
+namespace bf = boost::filesystem;
+
+namespace {
+
+constexpr char kCreateDirReqHandlerType[] = "createdir";
+
+} // namespace
+
+namespace res_handler {
+
+CreateDirRequestHandler::CreateDirRequestHandler(
+ std::string pkgid, uid_t uid, std::string root_path,
+ std::list<ResPathInfo> path_list) :
+ AbstractRequestHandler(pkgid, uid, root_path, path_list) {}
+
+ErrorType CreateDirRequestHandler::Execute() {
+ bf::path root_path(GetRootPath());
+ bf::path dst_root_path = root_path / "shared_res" / GetPkgID();
+
+ if (!CreateDir(dst_root_path, GetUID()))
+ return ErrorType::ERROR_SYSTEM_ERROR;
+
+ for (auto& path_info : GetPathList()) {
+ bf::path dst_path = dst_root_path / path_info.GetSrcPath();
+ if (!CreateDirs(GetPkgID(), dst_path, GetUID()))
+ return ErrorType::ERROR_SYSTEM_ERROR;
+ }
+
+ return ErrorType::ERROR_NONE;
+}
+
+const std::string CreateDirRequestHandler::GetRequestHandlerType() const {
+ return kCreateDirReqHandlerType;
+}
+
+} // namespace res_handler
#include "include/file_util.hh"
#include <fcntl.h>
+#include <grp.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <pwd.h>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
+#include <boost/optional.hpp>
#include <boost/system/error_code.hpp>
#include "include/logging.hh"
namespace bs = boost::system;
namespace bf = boost::filesystem;
+namespace {
+
+const int32_t kPWBufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
+const int32_t kGRBufSize = sysconf(_SC_GETGR_R_SIZE_MAX);
+
+} // namespace
+
namespace res_handler {
FSFlag operator|(FSFlag a, FSFlag b) {
return true;
}
-bool SetOwnership(const bf::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 false;
- }
- return true;
-}
-
-bool SetDirOwnershipAndPermissions(const boost::filesystem::path& path,
- boost::filesystem::perms permissions, uid_t uid,
- gid_t gid) {
- if (!SetOwnership(path, uid, gid)) {
- LOG(ERROR) << "Failed to change owner: " << path
- << "(" << uid << ", " << gid << ")";
- return false;
- }
- if (!SetDirPermissions(path, permissions)) {
- LOG(ERROR) << "Failed to change permission: " << path
- << std::oct << permissions;
- return false;
- }
-
- return true;
-}
-
bool CopyOwnershipAndPermissions(const boost::filesystem::path& src,
const boost::filesystem::path& dst) {
if (!bf::exists(src)) {
struct stat stats;
if (stat(src.c_str(), &stats) != 0)
return false;
+
if (!SetDirOwnershipAndPermissions(dst, permissions, stats.st_uid,
stats.st_gid)) {
LOG(ERROR) << "Failed to copy ownership and permissions"
bool CopyDir(const boost::filesystem::path& src,
const boost::filesystem::path& dst,
- FSFlag flags, bool skip_symlink) {
+ uid_t uid, FSFlag flags, bool skip_symlink) {
try {
// Check whether the function call is valid
if (!bf::exists(src) || !bf::is_directory(src)) {
}
if (!bf::exists(dst)) {
// Create the destination directory
- if (!CreateDir(dst)) {
+ if (!CreateDir(dst, uid)) {
LOG(ERROR) << "Unable to create destination directory" << dst;
return false;
}
}
} else if (bf::is_directory(current)) {
// Found directory: Recursion
- if (!CopyDir(current, target, flags, skip_symlink)) {
+ if (!CopyDir(current, target, uid, flags, skip_symlink)) {
return false;
}
} else {
return true;
}
-bool CreateDir(const bf::path& path) {
+bool CreateDir(const bf::path& path, uid_t uid) {
if (bf::exists(path))
return true;
boost::system::error_code error;
- bf::create_directories(path, error);
+ bf::create_directory(path, error);
if (error) {
LOG(ERROR) << "Failed to create directory: "
<< boost::system::system_error(error).what();
return false;
}
+
+ boost::optional<gid_t> gid = GetGidByUid(uid);
+ if (!gid)
+ return false;
+
+ bf::perms perms755 = bf::all_all ^ bf::group_write ^ bf::others_write;
+ if (!SetDirOwnershipAndPermissions(path, perms755, uid, *gid))
+ return false;
+
return true;
}
<< error.message() << "]";
return false;
}
+
+ if (!CopyOwnershipAndPermissions(src, dst)) {
+ LOG(ERROR) << "Failed set permission for file " << dst;
+ return false;
+ }
+
+ return true;
+}
+
+boost::optional<gid_t> GetGidByUid(uid_t uid) {
+ struct passwd pwd;
+ struct passwd* pwd_result;
+ char buf[kPWBufSize];
+ int ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwd_result);
+ if (ret != 0 || pwd_result == nullptr)
+ return {};
+ return pwd.pw_gid;
+}
+
+bool SetOwnership(const bf::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 false;
+ }
+ return true;
+}
+
+bool SetDirOwnershipAndPermissions(const boost::filesystem::path& path,
+ boost::filesystem::perms permissions, uid_t uid,
+ gid_t gid) {
+ if (!SetOwnership(path, uid, gid)) {
+ LOG(ERROR) << "Failed to change owner: " << path
+ << "(" << uid << ", " << gid << ")";
+ return false;
+ }
+ if (!SetDirPermissions(path, permissions)) {
+ LOG(ERROR) << "Failed to change permission: " << path
+ << std::oct << permissions;
+ return false;
+ }
+
+ return true;
+}
+
+bool CreateDirs(const std::string& pkgid, const boost::filesystem::path& path, uid_t uid) {
+ boost::system::error_code error;
+ bf::create_directories(path, error);
+
+ if (error) {
+ LOG(ERROR) << "Failed to create directory: "
+ << boost::system::system_error(error).what();
+ return false;
+ }
+
+ boost::optional<gid_t> gid = GetGidByUid(uid);
+ bf::perms perms755 = bf::all_all ^ bf::group_write ^ bf::others_write;
+ if (!gid)
+ return false;
+
+ bf::path target_path = path;
+ while(target_path.filename() != pkgid) {
+
+ if (!SetDirOwnershipAndPermissions(target_path, perms755, uid, *gid))
+ return false;
+
+ target_path = target_path.parent_path();
+ }
+
+ if (!SetDirOwnershipAndPermissions(target_path, perms755, uid, *gid))
+ return false;
+
return true;
}
("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)
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 == "remove" ||
+ o.string_key == "createdir") {
pkgid_ = o.value.front();
SetRequestType(o.string_key);
} else if (o.string_key == "help") {
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() {
namespace res_handler {
RemoveRequestHandler::RemoveRequestHandler(
- std::string pkgid, std::string root_path,
+ std::string pkgid, uid_t uid, std::string root_path,
std::list<ResPathInfo> path_list) :
- AbstractRequestHandler(pkgid, root_path, path_list) {}
+ AbstractRequestHandler(pkgid, uid, root_path, path_list) {}
ErrorType RemoveRequestHandler::Execute() {
bf::path root_path(GetRootPath());
#include "include/abstract_request_handler.hh"
#include "include/condition_validator.hh"
#include "include/copy_request_handler.hh"
+#include "include/createdir_request_handler.hh"
#include "include/event_signal_sender.hh"
#include "include/logging.hh"
#include "include/param_checker.hh"
handler_.reset(
new CopyRequestHandler(
option_.GetPkgID(),
+ option_.GetUID(),
GetRootPathForUid(option_.GetUID()),
option_.GetPathList()));
break;
handler_.reset(
new RemoveRequestHandler(
option_.GetPkgID(),
+ option_.GetUID(),
GetRootPathForUid(option_.GetUID()),
option_.GetPathList()));
break;
handler_.reset(
new UninstallRequestHandler(
option_.GetPkgID(),
+ option_.GetUID(),
+ GetRootPathForUid(option_.GetUID()),
+ option_.GetPathList()));
+ break;
+ case ReqType::REQ_TYPE_CREATEDIR:
+ handler_.reset(
+ new CreateDirRequestHandler(
+ option_.GetPkgID(),
+ option_.GetUID(),
GetRootPathForUid(option_.GetUID()),
option_.GetPathList()));
break;
namespace res_handler {
UninstallRequestHandler::UninstallRequestHandler(
- std::string pkgid, std::string root_path,
+ std::string pkgid, uid_t uid, std::string root_path,
std::list<ResPathInfo> path_list) :
- AbstractRequestHandler(pkgid, root_path, path_list) {}
+ AbstractRequestHandler(pkgid, uid, root_path, path_list) {}
ErrorType UninstallRequestHandler::Execute() {
if (GetPkgID().length() == 0) {
-this is second resource file
+this is second resource file
\ No newline at end of file
-this is 3rd resource file
+this is 3rd resource file
\ No newline at end of file
-this is resource file to being copied
+this is resource file to being copied
\ No newline at end of file
#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 "include/abstract_request_handler.hh"
#include "include/copy_request_handler.hh"
+#include "include/createdir_request_handler.hh"
#include "include/error_type.hh"
#include "include/param_checker.hh"
#include "include/remove_request_handler.hh"
using ::testing::SaveArg;
using res_handler::CopyRequestHandler;
+using res_handler::CreateDirRequestHandler;
using res_handler::RemoveRequestHandler;
using res_handler::ResPathInfo;
using res_handler::UninstallRequestHandler;
virtual void SetUp() {
bf::path rootpath(root_path);
+
bf::create_directories(
rootpath / "shared_res/test_pkg/dest_dir");
}
virtual void SetUp() {
bf::path rootpath(root_path);
+
bf::create_directories(
rootpath / "shared_res/test_pkg/new_dir/new_dir2");
std::string root_path = "./tests/unit_tests/res-copy/data";
};
+class CreateDirRequestHandlerTest : public TestFixture {
+ public:
+ CreateDirRequestHandlerTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~CreateDirRequestHandlerTest() {}
+
+ virtual void SetUp() {
+ bf::path rootpath(root_path);
+ bf::create_directories(
+ rootpath / "shared_res/test_pkg/existed_dir");
+ }
+ virtual void TearDown() {
+ bf::remove_all("./tests/unit_tests/res-copy/data/shared_res/test_pkg");
+ }
+
+ std::string root_path = "./tests/unit_tests/res-copy/data";
+};
+
TEST_F(CopyRequestHandlerTest, CopyFileAtRootToRoot) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_file.txt", "");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyFileAtRootToRoot_ChangeFileName) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_file.txt", "another_name.txt");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyFileAtRootToDirectory) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_file.txt", "dest_dir");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyFileAtRootToDirectory_ChangeFileName) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_file.txt", "dest_dir/newname.txt");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyFileAtDirectoryToRoot) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1/resource_file3.txt", "");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
std::list<ResPathInfo> path_list;
path_list.emplace_back(
"data/resource_dir1/resource_file3.txt", "newname.txt");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyFileAtDirectoryToDirectory) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1/resource_file3.txt", "dest_dir");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
std::list<ResPathInfo> path_list;
path_list.emplace_back(
"data/resource_dir1/resource_file3.txt", "dest_dir/newname.txt");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToRoot) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1", "");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", getuid(), root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToDirectory) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1", "dest_dir");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", getuid(), root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToDirectory2) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1", "resource_dir1");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", getuid(), root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtDirectoryToRoot) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1/resource_dir2", "");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtDirectoryToDirectory) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1/resource_dir2", "dest_dir");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
TEST_F(CopyRequestHandlerTest, ResNotexists) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/not_existed_res", "new_dir");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_RES_NOT_FOUND);
}
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_file.txt", "new_dir");
- CopyRequestHandler handler("test_pkg", root_path, path_list);
+ CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- CopyRequestHandler replace_handler("test_pkg", root_path, path_list);
+ CopyRequestHandler replace_handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
}
std::list<ResPathInfo> path_list;
path_list.emplace_back("resource_file.txt", "");
- RemoveRequestHandler handler("test_pkg", root_path, path_list);
+ RemoveRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
bf::path check_path(root_path + "/shared_res/test_pkg/resource_file.txt");
std::list<ResPathInfo> path_list;
path_list.emplace_back("new_dir/resource_file.txt", "");
- RemoveRequestHandler handler("test_pkg", root_path, path_list);
+ RemoveRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
bf::path check_path(
std::list<ResPathInfo> path_list;
path_list.emplace_back("new_dir", "");
- RemoveRequestHandler handler("test_pkg", root_path, path_list);
+ RemoveRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
bf::path check_path(root_path + "/shared_res/test_pkg/new_dir");
std::list<ResPathInfo> path_list;
path_list.emplace_back("new_dir/new_dir2", "");
- RemoveRequestHandler handler("test_pkg", root_path, path_list);
+ RemoveRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
bf::path check_path(root_path + "/shared_res/test_pkg/new_dir/new_dir2");
TEST_F(UninstallRequestHandlerTest, RemoveRootPath) {
std::list<ResPathInfo> path_list;
- UninstallRequestHandler handler("test_pkg", root_path, path_list);
+ UninstallRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
bf::path check_path(root_path + "/shared_res/test_pkg/");
bf::path check_path(root_path + "/shared_res/test_pkg/");
bf::remove_all(check_path);
- UninstallRequestHandler handler("test_pkg", root_path, path_list);
+ UninstallRequestHandler handler("test_pkg", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
}
TEST_F(UninstallRequestHandlerTest, EmptyPkgID) {
std::list<ResPathInfo> path_list;
- UninstallRequestHandler handler("", root_path, path_list);
+ UninstallRequestHandler handler("", 0, root_path, path_list);
EXPECT_EQ(handler.Execute(),
res_handler::ErrorType::ERROR_INVALID_PARAMETER);
}
+
+TEST_F(CreateDirRequestHandlerTest, CreateOneAtRoot) {
+ std::list<ResPathInfo> path_list;
+ path_list.emplace_back("new_dir", "");
+
+ CreateDirRequestHandler handler("test_pkg", getuid(), root_path, path_list);
+ EXPECT_EQ(handler.Execute(),
+ res_handler::ErrorType::ERROR_NONE);
+
+ bf::path check_path(root_path + "/shared_res/test_pkg/new_dir");
+ EXPECT_TRUE(bf::exists(check_path));
+}
+
+TEST_F(CreateDirRequestHandlerTest, CreateOneAtExistedDirectory) {
+ std::list<ResPathInfo> path_list;
+ path_list.emplace_back("existed_dir/new_dir", "");
+
+ CreateDirRequestHandler handler("test_pkg", getuid(), root_path, path_list);
+ EXPECT_EQ(handler.Execute(),
+ res_handler::ErrorType::ERROR_NONE);
+
+ bf::path check_path(root_path + "/shared_res/test_pkg/existed_dir/new_dir");
+ EXPECT_TRUE(bf::exists(check_path));
+}
+
+TEST_F(CreateDirRequestHandlerTest, CreateHierachyAtRoot) {
+ std::list<ResPathInfo> path_list;
+ path_list.emplace_back("new_dir/another_new_dir", "");
+
+ CreateDirRequestHandler handler("test_pkg", getuid(), root_path, path_list);
+ EXPECT_EQ(handler.Execute(),
+ res_handler::ErrorType::ERROR_NONE);
+
+ bf::path check_path(root_path + "/shared_res/test_pkg/new_dir");
+ EXPECT_TRUE(bf::exists(check_path));
+
+ check_path /= "another_new_dir";
+ EXPECT_TRUE(bf::exists(check_path));
+}
+
+
+TEST_F(CreateDirRequestHandlerTest, CreateHierachyAtExistedDirectory) {
+ std::list<ResPathInfo> path_list;
+ path_list.emplace_back("existed_dir/new_dir/another_new_dir", "");
+
+ CreateDirRequestHandler handler("test_pkg", getuid(), root_path, path_list);
+ EXPECT_EQ(handler.Execute(),
+ res_handler::ErrorType::ERROR_NONE);
+
+ bf::path check_path(root_path + "/shared_res/test_pkg/existed_dir/new_dir");
+ EXPECT_TRUE(bf::exists(check_path));
+
+ check_path /= "another_new_dir";
+ EXPECT_TRUE(bf::exists(check_path));
+}
EXPECT_EQ(request_handler_invoker.GetHandlerType(), "delete");
}
+TEST_F(RequestHandlerInvokerTest, CreateDirType) {
+ const char *argv[] = { "/bin/res-copy", "--uid", "5001", "-D",
+ "org.test.targetpkgid", "-p", "newdir", nullptr};
+ ParamChecker checker(7, (char**)argv);
+
+ RequestHandlerInvoker request_handler_invoker(checker, signal_sender_);
+ EXPECT_EQ(request_handler_invoker.GetHandlerType(), "createdir");
+}
+
TEST_F(RequestHandlerInvokerTest, InvalidType) {
const char *argv[] = { "/bin/res-copy", "--uid", "5001", nullptr};
ParamChecker checker(3, (char**)argv);