Compare commits
2 Commits
54b70f99cc
...
80d8d6f32f
Author | SHA1 | Date | |
---|---|---|---|
80d8d6f32f | |||
0b7a9c6a56 |
@@ -118,18 +118,8 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
|
||||
|
||||
auto is_create_op = ((file_info->flags & O_CREAT) == O_CREAT);
|
||||
auto is_directory_op = ((file_info->flags & O_DIRECTORY) == O_DIRECTORY);
|
||||
auto is_truncate_op = ((file_info->flags & O_TRUNC) == O_TRUNC);
|
||||
auto is_exclusive = ((file_info->flags & O_EXCL) == O_EXCL);
|
||||
|
||||
if (((file_info->flags & O_WRONLY) != 0) ||
|
||||
((file_info->flags & O_RDWR) != 0)) {
|
||||
auto res = provider_.is_file_writeable(api_path)
|
||||
? api_error::success
|
||||
: api_error::permission_denied;
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
auto is_truncate_op = ((file_info->flags & O_TRUNC) == O_TRUNC);
|
||||
|
||||
auto res = check_parent_access(api_path, X_OK);
|
||||
if (res != api_error::success) {
|
||||
@@ -152,6 +142,12 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((((file_info->flags & O_WRONLY) == O_WRONLY) ||
|
||||
((file_info->flags & O_RDWR) == O_RDWR)) &&
|
||||
not provider_.is_file_writeable(api_path)) {
|
||||
return api_error::permission_denied;
|
||||
}
|
||||
|
||||
if (is_create_op && is_directory_op) {
|
||||
return api_error::invalid_operation;
|
||||
}
|
||||
@@ -162,17 +158,23 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
|
||||
return res;
|
||||
}
|
||||
|
||||
if (is_create_op) {
|
||||
if (is_exclusive && file_exists) {
|
||||
return api_error::item_exists;
|
||||
}
|
||||
} else {
|
||||
bool dir_exists{};
|
||||
bool dir_exists{};
|
||||
if (not file_exists) {
|
||||
res = provider_.is_directory(api_path, dir_exists);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_create_op) {
|
||||
if (dir_exists) {
|
||||
return api_error::directory_exists;
|
||||
}
|
||||
|
||||
if (is_exclusive && file_exists) {
|
||||
return api_error::item_exists;
|
||||
}
|
||||
} else {
|
||||
if (not(is_directory_op ? dir_exists : file_exists)) {
|
||||
return (is_directory_op ? api_error::directory_not_found
|
||||
: api_error::item_not_found);
|
||||
|
@@ -176,8 +176,8 @@ auto fuse_drive_base::check_parent_access(const std::string &api_path,
|
||||
for (auto parent = utils::path::get_parent_path(api_path);
|
||||
(ret == api_error::success) && not parent.empty();
|
||||
parent = utils::path::get_parent_path(parent)) {
|
||||
if (((ret = check_access(parent, X_OK)) == api_error::success) &&
|
||||
(parent == "/")) {
|
||||
ret = check_access(parent, X_OK);
|
||||
if ((ret == api_error::success) && (parent == "/")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -378,6 +378,97 @@ TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl) {
|
||||
|
||||
this->unlink_file_and_test(file_path);
|
||||
}
|
||||
|
||||
// 1. O_CREAT-Failure: ENOENT (No such file or directory) if the parent
|
||||
// directory doesn’t exist.
|
||||
TYPED_TEST(fuse_test, create_fails_if_parent_does_not_exist) {
|
||||
std::string file_name{"no_dir/create_test"};
|
||||
auto file_path = this->create_file_path(file_name);
|
||||
|
||||
auto handle = open(file_path.c_str(), O_CREAT, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
EXPECT_EQ(ENOENT, errno);
|
||||
}
|
||||
|
||||
// 1. O_CREAT-Failure: EISDIR (Is a directory) if a directory exists instead of
|
||||
// a file.
|
||||
TYPED_TEST(fuse_test, create_fails_if_path_is_directory) {
|
||||
std::string dir_name{"create_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name);
|
||||
|
||||
auto handle = open(dir_path.c_str(), O_CREAT, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
EXPECT_EQ(EISDIR, errno);
|
||||
|
||||
this->rmdir_and_test(dir_path);
|
||||
}
|
||||
|
||||
// 2. O_CREAT|O_TRUNC-Failure: ENOENT (No such file or directory) if the parent
|
||||
// directory doesn’t exist.
|
||||
TYPED_TEST(fuse_test, create_fails_with_trunc_if_parent_does_not_exist) {
|
||||
std::string file_name{"no_dir/create_test"};
|
||||
auto file_path = this->create_file_path(file_name);
|
||||
|
||||
auto handle = open(file_path.c_str(), O_CREAT | O_TRUNC, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
EXPECT_EQ(ENOENT, errno);
|
||||
}
|
||||
|
||||
// 2. O_CREAT|O_TRUNC-Failure: EISDIR (Is a directory) if a directory exists
|
||||
// instead of a file.
|
||||
TYPED_TEST(fuse_test, create_fails_with_trunc_if_path_is_directory) {
|
||||
std::string dir_name{"create_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name);
|
||||
|
||||
auto handle = open(dir_path.c_str(), O_CREAT | O_TRUNC, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
EXPECT_EQ(EISDIR, errno);
|
||||
|
||||
this->rmdir_and_test(dir_path);
|
||||
}
|
||||
|
||||
// 3. O_CREAT|O_EXCL-Failure: ENOENT (No such file or directory) if the parent
|
||||
// directory doesn’t exist.
|
||||
TYPED_TEST(fuse_test, create_fails_with_excl_if_parent_does_not_exist) {
|
||||
std::string file_name{"no_dir/create_test"};
|
||||
auto file_path = this->create_file_path(file_name);
|
||||
|
||||
auto handle = open(file_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
EXPECT_EQ(ENOENT, errno);
|
||||
}
|
||||
|
||||
// 3. O_CREAT|O_EXCL-Failure: EEXIST (File exists) if the file already exists.
|
||||
TYPED_TEST(fuse_test, create_fails_with_excl_if_file_exists) {
|
||||
std::string file_name{"create_test"};
|
||||
auto file_path = this->create_file_and_test(file_name);
|
||||
|
||||
auto handle = open(file_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
EXPECT_EQ(EEXIST, errno);
|
||||
|
||||
this->unlink_file_and_test(file_path);
|
||||
}
|
||||
|
||||
// 3. O_CREAT|O_EXCL-Failure: EEXIST (File exists) if the file or directory
|
||||
// already exists.
|
||||
TYPED_TEST(fuse_test, create_fails_with_excl_if_path_is_directory) {
|
||||
std::string dir_name{"create_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name);
|
||||
|
||||
auto handle = open(dir_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
EXPECT_EQ(EEXIST, errno);
|
||||
|
||||
this->rmdir_and_test(dir_path);
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // !defined(_WIN32)
|
||||
|
Reference in New Issue
Block a user