fix truncate
All checks were successful
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good
This commit is contained in:
parent
8555d31ddf
commit
dc48b84191
@ -159,29 +159,32 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t handle{};
|
std::uint64_t handle{};
|
||||||
std::shared_ptr<i_open_file> open_file;
|
{
|
||||||
if (is_create_op) {
|
std::shared_ptr<i_open_file> open_file;
|
||||||
const auto now = utils::get_file_time_now();
|
if (is_create_op) {
|
||||||
|
const auto now = utils::get_file_time_now();
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
const auto osx_flags = static_cast<std::uint32_t>(file_info->flags);
|
const auto osx_flags = static_cast<std::uint32_t>(file_info->flags);
|
||||||
#else
|
#else
|
||||||
const auto osx_flags = 0U;
|
const auto osx_flags = 0U;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto meta = create_meta_attributes(
|
auto meta = create_meta_attributes(
|
||||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now, now,
|
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now, now,
|
||||||
is_directory_op, get_effective_gid(), "", mode, now, 0U, osx_flags, 0U,
|
is_directory_op, get_effective_gid(), "", mode, now, 0U, osx_flags,
|
||||||
utils::path::combine(config_.get_cache_directory(),
|
0U,
|
||||||
{utils::create_uuid_string()}),
|
utils::path::combine(config_.get_cache_directory(),
|
||||||
get_effective_uid(), now);
|
{utils::create_uuid_string()}),
|
||||||
|
get_effective_uid(), now);
|
||||||
|
|
||||||
res = fm_->create(api_path, meta, file_info->flags, handle, open_file);
|
res = fm_->create(api_path, meta, file_info->flags, handle, open_file);
|
||||||
if ((res != api_error::item_exists) && (res != api_error::success)) {
|
if ((res != api_error::item_exists) && (res != api_error::success)) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} else if (((res = fm_->open(api_path, is_directory_op, file_info->flags,
|
||||||
|
handle, open_file)) != api_error::success)) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} else if (((res = fm_->open(api_path, is_directory_op, file_info->flags,
|
|
||||||
handle, open_file)) != api_error::success)) {
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file_info->fh = handle;
|
file_info->fh = handle;
|
||||||
@ -1242,17 +1245,18 @@ auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
open_file_data ofd{O_RDWR};
|
|
||||||
std::uint64_t handle{};
|
std::uint64_t handle{};
|
||||||
std::shared_ptr<i_open_file> open_file;
|
{
|
||||||
if ((res = fm_->open(api_path, false, ofd, handle, open_file)) !=
|
open_file_data ofd{O_RDWR};
|
||||||
api_error::success) {
|
std::shared_ptr<i_open_file> open_file;
|
||||||
return res;
|
if ((res = fm_->open(api_path, false, ofd, handle, open_file)) !=
|
||||||
|
api_error::success) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = open_file->resize(static_cast<std::uint64_t>(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
res = open_file->resize(static_cast<std::uint64_t>(size));
|
|
||||||
fm_->close(handle);
|
fm_->close(handle);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ void file_manager::close_timed_out_files() {
|
|||||||
for (const auto &api_path : closeable_list) {
|
for (const auto &api_path : closeable_list) {
|
||||||
auto closeable_file = open_file_lookup_.at(api_path);
|
auto closeable_file = open_file_lookup_.at(api_path);
|
||||||
open_file_lookup_.erase(api_path);
|
open_file_lookup_.erase(api_path);
|
||||||
open_files.push_back(std::move(closeable_file));
|
open_files.push_back(closeable_file);
|
||||||
}
|
}
|
||||||
closeable_list.clear();
|
closeable_list.clear();
|
||||||
file_lock.unlock();
|
file_lock.unlock();
|
||||||
@ -434,8 +434,8 @@ void file_manager::queue_upload(const std::string &api_path,
|
|||||||
|
|
||||||
auto file_manager::remove_file(const std::string &api_path) -> api_error {
|
auto file_manager::remove_file(const std::string &api_path) -> api_error {
|
||||||
recur_mutex_lock open_lock(open_file_mtx_);
|
recur_mutex_lock open_lock(open_file_mtx_);
|
||||||
auto it = open_file_lookup_.find(api_path);
|
auto iter = open_file_lookup_.find(api_path);
|
||||||
if (it != open_file_lookup_.end() && it->second->is_modified()) {
|
if (iter != open_file_lookup_.end() && iter->second->is_modified()) {
|
||||||
return api_error::file_in_use;
|
return api_error::file_in_use;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,14 +445,13 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_upload(api_path);
|
||||||
|
close_all(api_path);
|
||||||
|
|
||||||
if ((res = provider_.remove_file(api_path)) != api_error::success) {
|
if ((res = provider_.remove_file(api_path)) != api_error::success) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_upload(api_path);
|
|
||||||
|
|
||||||
close_all(api_path);
|
|
||||||
|
|
||||||
if (not utils::file::retry_delete_file(fsi.source_path)) {
|
if (not utils::file::retry_delete_file(fsi.source_path)) {
|
||||||
utils::error::raise_api_path_error(
|
utils::error::raise_api_path_error(
|
||||||
__FUNCTION__, fsi.api_path, fsi.source_path,
|
__FUNCTION__, fsi.api_path, fsi.source_path,
|
||||||
|
@ -233,6 +233,8 @@ auto file_manager::open_file_base::close() -> bool {
|
|||||||
io_thread_.reset();
|
io_thread_.reset();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
io_thread_notify_.notify_all();
|
io_thread_notify_.notify_all();
|
||||||
|
@ -519,15 +519,16 @@ static void test_xattr_removexattr(const std::string &file_path) {
|
|||||||
TEST(fuse_drive, all_tests) {
|
TEST(fuse_drive, all_tests) {
|
||||||
auto current_directory = std::filesystem::current_path();
|
auto current_directory = std::filesystem::current_path();
|
||||||
|
|
||||||
for (std::size_t idx = 0U; idx < 2U; idx++) {
|
for (std::size_t idx = 1U; idx < 2U; idx++) {
|
||||||
std::filesystem::current_path(current_directory);
|
std::filesystem::current_path(current_directory);
|
||||||
|
|
||||||
const auto test_directory =
|
const auto test_directory =
|
||||||
utils::path::absolute("./fuse_drive" + std::to_string(idx));
|
utils::path::absolute("./fuse_drive" + std::to_string(idx));
|
||||||
|
EXPECT_TRUE(utils::file::delete_directory_recursively(test_directory));
|
||||||
|
|
||||||
const auto mount_location = utils::path::absolute(
|
const auto mount_location = utils::path::absolute(
|
||||||
utils::path::combine(test_directory, {"mount", std::to_string(idx)}));
|
utils::path::combine(test_directory, {"mount", std::to_string(idx)}));
|
||||||
EXPECT_TRUE(utils::file::delete_directory_recursively(mount_location));
|
|
||||||
EXPECT_TRUE(utils::file::create_full_directory_path(mount_location));
|
EXPECT_TRUE(utils::file::create_full_directory_path(mount_location));
|
||||||
{
|
{
|
||||||
std::unique_ptr<app_config> config_ptr{};
|
std::unique_ptr<app_config> config_ptr{};
|
||||||
@ -536,7 +537,6 @@ TEST(fuse_drive, all_tests) {
|
|||||||
|
|
||||||
const auto cfg_directory = utils::path::absolute(
|
const auto cfg_directory = utils::path::absolute(
|
||||||
utils::path::combine(test_directory, {"cfg", std::to_string(idx)}));
|
utils::path::combine(test_directory, {"cfg", std::to_string(idx)}));
|
||||||
EXPECT_TRUE(utils::file::delete_directory_recursively(cfg_directory));
|
|
||||||
EXPECT_TRUE(utils::file::create_full_directory_path(cfg_directory));
|
EXPECT_TRUE(utils::file::create_full_directory_path(cfg_directory));
|
||||||
|
|
||||||
std::vector<std::string> drive_args{};
|
std::vector<std::string> drive_args{};
|
||||||
@ -704,9 +704,6 @@ TEST(fuse_drive, all_tests) {
|
|||||||
drive_args.push_back(mount_location);
|
drive_args.push_back(mount_location);
|
||||||
execute_mount(config_ptr->get_data_directory(), drive_args, th);
|
execute_mount(config_ptr->get_data_directory(), drive_args, th);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_TRUE(utils::file::delete_directory_recursively(mount_location));
|
|
||||||
EXPECT_TRUE(utils::file::delete_directory_recursively(test_directory));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::current_path(current_directory);
|
std::filesystem::current_path(current_directory);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user