namespace {
-const int32_t kPWBufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
-const int32_t kGRBufSize = sysconf(_SC_GETGR_R_SIZE_MAX);
+constexpr uid_t kRootUID = 0;
+constexpr gid_t kPrivPlatformGid = 10212;
+constexpr mode_t kDefaultMode640 = S_IRUSR | S_IWUSR | S_IRGRP;
} // namespace
}
bool SetDirPermissions(const boost::filesystem::path& path,
- boost::filesystem::perms permissions) {
- boost::system::error_code error;
- bf::permissions(path, permissions, error);
-
- if (error) {
- LOG(ERROR) << "Failed to set permissions for directory: " << path
- << boost::system::system_error(error).what();
+ mode_t mode) {
+ if (chmod(path.string().c_str(), mode) != 0) {
+ LOG(ERROR) << "Failed to set permissions for path: " << path
+ << ", errno : " << errno;
return false;
}
- return true;
-}
-bool CopyOwnershipAndPermissions(const boost::filesystem::path& src,
- const boost::filesystem::path& dst) {
- if (!bf::exists(src)) {
- LOG(ERROR) << "Failed to copy ownership and permissions"
- << " from " << src << " to " << dst;
- return false;
- }
- bf::perms permissions = bf::status(src).permissions();
- 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"
- << " from " << src << " to " << dst;
- return false;
- }
return true;
}
bool CopyDir(const boost::filesystem::path& src,
const boost::filesystem::path& dst,
- uid_t uid, FSFlag flags, bool skip_symlink) {
+ 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, uid)) {
+ if (!CreateDir(dst)) {
LOG(ERROR) << "Unable to create destination directory" << dst;
return false;
}
- if (flags & FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS)
- CopyOwnershipAndPermissions(src, dst);
} else {
if (!(flags & (FS_MERGE_SKIP | FS_MERGE_OVERWRITE))) {
LOG(ERROR) << "Destination directory " << dst.string()
<< " already exists.";
return false;
}
- if (flags & (FS_MERGE_OVERWRITE | FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS))
- CopyOwnershipAndPermissions(src, dst);
}
} catch (const bf::filesystem_error& error) {
LOG(ERROR) << "Failed to copy directory: " << error.what();
}
} else if (bf::is_directory(current)) {
// Found directory: Recursion
- if (!CopyDir(current, target, uid, flags, skip_symlink)) {
+ if (!CopyDir(current, target, flags, skip_symlink)) {
return false;
}
} else {
else
bf::copy_file(current, destination);
- if (flags & FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS)
- CopyOwnershipAndPermissions(current, destination);
-
if (flags & FS_COMMIT_COPY_FILE) {
if (flags & FS_MERGE_OVERWRITE)
bf::remove(target);
+
bf::rename(destination, target);
}
}
return true;
}
-bool CreateDir(const bf::path& path, uid_t uid) {
+bool CreateDir(const bf::path& path) {
if (bf::exists(path))
return true;
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))
+ if (!SetDirOwnershipAndPermissions(
+ path, kDefaultMode640, kRootUID, kPrivPlatformGid))
return false;
return true;
}
bool CopyFile(const bf::path& src, const bf::path& dst) {
- bs::error_code error;
+ if (bf::is_symlink(bf::symlink_status(src)))
+ return true;
+ bs::error_code error;
bf::copy_file(src, dst, bf::copy_option::overwrite_if_exists, error);
if (error) {
LOG(WARNING) << "copy file " << src << " due to error ["
return false;
}
- if (!CopyOwnershipAndPermissions(src, dst)) {
+ if (!SetDirOwnershipAndPermissions(
+ dst, kDefaultMode640, kRootUID, kPrivPlatformGid)) {
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;
+ std::cerr << "jungh failed to set lchown : " << ret << std::endl;
return false;
}
return true;
}
bool SetDirOwnershipAndPermissions(const boost::filesystem::path& path,
- boost::filesystem::perms permissions, uid_t uid,
- gid_t gid) {
+ mode_t mode, 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;
+ if (!SetDirPermissions(path, mode)) {
+ LOG(ERROR) << "Failed to change permission: " << path;
return false;
}
return true;
}
-bool CreateDirs(const std::string& pkgid, const boost::filesystem::path& path, uid_t uid) {
+bool CreateDirs(
+ const std::string& pkgid, const boost::filesystem::path& path) {
boost::system::error_code error;
bf::create_directories(path, error);
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))
+ if (!SetDirOwnershipAndPermissions(
+ target_path, kDefaultMode640, kRootUID, kPrivPlatformGid))
return false;
target_path = target_path.parent_path();
}
- if (!SetDirOwnershipAndPermissions(target_path, perms755, uid, *gid))
- return false;
+ if (!SetDirOwnershipAndPermissions(
+ target_path, kDefaultMode640, kRootUID, kPrivPlatformGid))
+ return false;
return true;
}
namespace bf = boost::filesystem;
namespace bs = boost::system;
+namespace {
+
+constexpr char kTestPkgID[] = "test_pkg";
+
+std::string GetTestPkgID() {
+ return kTestPkgID;
+}
+
+std::string GetRootPath() {
+ return "./tests/unit_tests/res-copy/data";
+}
+
+bf::path GetSrcRootPath() {
+ return bf::path(GetRootPath()) / "apps_rw" / kTestPkgID;
+}
+
+bf::path GetDstRootPath() {
+ return bf::path(GetRootPath()) / "priv_shared_res" / kTestPkgID;
+}
+
+} // namespace
+
class Mocks : public ::testing::NiceMock<PkgMgrInfoMock>,
public ::testing::NiceMock<OsMock> {};
virtual ~CopyRequestHandlerTest() {}
virtual void SetUp() {
- bf::path rootpath(root_path);
+ bf::create_directories(GetDstRootPath() / "dest_dir");
- bf::create_directories(
- rootpath / "shared_res/test_pkg/dest_dir");
+ EXPECT_CALL(GetMock<OsMock>(), lchown(_, _, _)).WillRepeatedly(Return(0));
+ EXPECT_CALL(GetMock<OsMock>(), chmod(_, _)).WillRepeatedly(Return(0));
}
virtual void TearDown() {
- bf::remove_all("./tests/unit_tests/res-copy/data/shared_res/test_pkg");
+ bf::remove_all(GetDstRootPath());
}
-
- std::string root_path = "./tests/unit_tests/res-copy/data";
};
class RemoveRequestHandlerTest : public TestFixture {
virtual ~RemoveRequestHandlerTest() {}
virtual void SetUp() {
- bf::path rootpath(root_path);
-
- bf::create_directories(
- rootpath / "shared_res/test_pkg/new_dir/new_dir2");
-
- bf::copy_file(rootpath / "apps_rw/test_pkg/data/resource_file.txt",
- rootpath / "shared_res/test_pkg/resource_file.txt");
-
- bf::copy_file(rootpath / "apps_rw/test_pkg/data/resource_file.txt",
- rootpath / "shared_res/test_pkg/new_dir/resource_file.txt");
-
- bf::copy_file(rootpath / "apps_rw/test_pkg/data/resource_file.txt",
- rootpath / "shared_res/test_pkg/new_dir/new_dir2/resource_file.txt");
+ bf::create_directories(GetDstRootPath() / "new_dir/new_dir2");
+ bf::copy_file(GetSrcRootPath() / "data/resource_file.txt",
+ GetDstRootPath() / "resource_file.txt");
+ bf::copy_file(GetSrcRootPath() / "data/resource_file.txt",
+ GetDstRootPath() / "new_dir/resource_file.txt");
+ bf::copy_file(GetSrcRootPath() / "data/resource_file.txt",
+ GetDstRootPath() / "new_dir/new_dir2/resource_file.txt");
}
virtual void TearDown() {
- bf::remove_all("./tests/unit_tests/res-copy/data/shared_res/test_pkg");
+ bf::remove_all(GetDstRootPath());
}
-
- std::string root_path = "./tests/unit_tests/res-copy/data";
};
class UninstallRequestHandlerTest : public TestFixture {
virtual ~UninstallRequestHandlerTest() {}
virtual void SetUp() {
- bf::path rootpath(root_path);
- bf::create_directories(
- rootpath / "shared_res/test_pkg");
+ bf::create_directories(GetDstRootPath());
}
+
virtual void TearDown() {
- bf::remove_all("./tests/unit_tests/res-copy/data/shared_res/test_pkg");
+ bf::remove_all(GetDstRootPath());
}
-
- std::string root_path = "./tests/unit_tests/res-copy/data";
};
class CreateDirRequestHandlerTest : public TestFixture {
virtual ~CreateDirRequestHandlerTest() {}
virtual void SetUp() {
- bf::path rootpath(root_path);
- bf::create_directories(
- rootpath / "shared_res/test_pkg/existed_dir");
+ bf::create_directories(GetDstRootPath() / "existed_dir");
}
+
virtual void TearDown() {
- bf::remove_all("./tests/unit_tests/res-copy/data/shared_res/test_pkg");
+ bf::remove_all(GetDstRootPath());
}
-
- 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", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "resource_file.txt";
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", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "another_name.txt";
TEST_F(CopyRequestHandlerTest, CopyFileAtRootToDirectory) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_file.txt", "dest_dir");
- CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "dest_dir";
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", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "dest_dir";
TEST_F(CopyRequestHandlerTest, CopyFileAtDirectoryToRoot) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1/resource_file3.txt", "");
- CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "resource_file3.txt";
std::list<ResPathInfo> path_list;
path_list.emplace_back(
"data/resource_dir1/resource_file3.txt", "newname.txt");
- CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "newname.txt";
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", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "dest_dir";
std::list<ResPathInfo> path_list;
path_list.emplace_back(
"data/resource_dir1/resource_file3.txt", "dest_dir/newname.txt");
- CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "dest_dir";
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToRoot) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1", "");
- CopyRequestHandler handler("test_pkg", getuid(), root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "resource_file3.txt";
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToDirectory) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1", "dest_dir");
- CopyRequestHandler handler("test_pkg", getuid(), root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "dest_dir";
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtRootToDirectory2) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1", "resource_dir1");
- CopyRequestHandler handler("test_pkg", getuid(), root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "resource_dir1";
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtDirectoryToRoot) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1/resource_dir2", "");
- CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "resource_file2.txt";
TEST_F(CopyRequestHandlerTest, CopyDirectoryAtDirectoryToDirectory) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/resource_dir1/resource_dir2", "dest_dir");
- CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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 = GetDstRootPath();
EXPECT_TRUE(bf::exists(check_path));
check_path /= "dest_dir";
TEST_F(CopyRequestHandlerTest, ResNotexists) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("data/not_existed_res", "new_dir");
- CopyRequestHandler handler("test_pkg", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), 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", 0, root_path, path_list);
+ CopyRequestHandler handler(GetTestPkgID(), 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- CopyRequestHandler replace_handler("test_pkg", 0, root_path, path_list);
- EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
+ CopyRequestHandler replace_handler(
+ GetTestPkgID(), 0, GetRootPath(), path_list);
+ EXPECT_EQ(replace_handler.Execute(), res_handler::ErrorType::ERROR_NONE);
}
TEST_F(RemoveRequestHandlerTest, RemoveFileAtRoot) {
std::list<ResPathInfo> path_list;
path_list.emplace_back("resource_file.txt", "");
- RemoveRequestHandler handler("test_pkg", 0, root_path, path_list);
+ RemoveRequestHandler handler("test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(root_path + "/shared_res/test_pkg/resource_file.txt");
+ bf::path check_path(GetDstRootPath() / "resource_file.txt");
EXPECT_FALSE(bf::exists(check_path));
}
std::list<ResPathInfo> path_list;
path_list.emplace_back("new_dir/resource_file.txt", "");
- RemoveRequestHandler handler("test_pkg", 0, root_path, path_list);
+ RemoveRequestHandler handler("test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(
- root_path + "/shared_res/test_pkg/new_dir/resource_file.txt");
+ bf::path check_path(GetDstRootPath() / "new_dir/resource_file.txt");
EXPECT_FALSE(bf::exists(check_path));
}
std::list<ResPathInfo> path_list;
path_list.emplace_back("new_dir", "");
- RemoveRequestHandler handler("test_pkg", 0, root_path, path_list);
+ RemoveRequestHandler handler("test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(root_path + "/shared_res/test_pkg/new_dir");
+ bf::path check_path(GetDstRootPath() / "new_dir");
EXPECT_FALSE(bf::exists(check_path));
}
std::list<ResPathInfo> path_list;
path_list.emplace_back("new_dir/new_dir2", "");
- RemoveRequestHandler handler("test_pkg", 0, root_path, path_list);
+ RemoveRequestHandler handler("test_pkg", 0, GetRootPath(), 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");
+ bf::path check_path(GetDstRootPath() / "new_dir/new_dir2");
EXPECT_FALSE(bf::exists(check_path));
}
TEST_F(UninstallRequestHandlerTest, RemoveRootPath) {
std::list<ResPathInfo> path_list;
- UninstallRequestHandler handler("test_pkg", 0, root_path, path_list);
+ UninstallRequestHandler handler(
+ "test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
-
- bf::path check_path(root_path + "/shared_res/test_pkg/");
- EXPECT_FALSE(bf::exists(check_path));
+ EXPECT_FALSE(bf::exists(GetDstRootPath()));
}
TEST_F(UninstallRequestHandlerTest, RootNotExists) {
std::list<ResPathInfo> path_list;
- bf::path check_path(root_path + "/shared_res/test_pkg/");
- bf::remove_all(check_path);
+ bf::remove_all(GetDstRootPath());
- UninstallRequestHandler handler("test_pkg", 0, root_path, path_list);
+ UninstallRequestHandler handler(
+ "test_pkg", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(), res_handler::ErrorType::ERROR_NONE);
}
TEST_F(UninstallRequestHandlerTest, EmptyPkgID) {
std::list<ResPathInfo> path_list;
- UninstallRequestHandler handler("", 0, root_path, path_list);
+ UninstallRequestHandler handler("", 0, GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(),
res_handler::ErrorType::ERROR_INVALID_PARAMETER);
}
std::list<ResPathInfo> path_list;
path_list.emplace_back("new_dir", "");
- CreateDirRequestHandler handler("test_pkg", getuid(), root_path, path_list);
+ CreateDirRequestHandler handler(
+ "test_pkg", getuid(), GetRootPath(), 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));
+ EXPECT_TRUE(bf::exists(GetDstRootPath() / "new_dir"));
}
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);
+ CreateDirRequestHandler handler(
+ "test_pkg", getuid(), GetRootPath(), 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));
+ EXPECT_TRUE(bf::exists(GetDstRootPath() / "existed_dir/new_dir"));
}
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);
+ CreateDirRequestHandler handler(
+ "test_pkg", getuid(), GetRootPath(), path_list);
EXPECT_EQ(handler.Execute(),
res_handler::ErrorType::ERROR_NONE);
- bf::path check_path(root_path + "/shared_res/test_pkg/new_dir");
+ bf::path check_path(GetDstRootPath() / "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);
+ CreateDirRequestHandler handler(
+ "test_pkg", getuid(), GetRootPath(), 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");
+ bf::path check_path(GetDstRootPath() / "existed_dir/new_dir");
EXPECT_TRUE(bf::exists(check_path));
check_path /= "another_new_dir";