fix truncate
All checks were successful
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2023-11-18 19:07:53 -06:00
parent 8555d31ddf
commit dc48b84191
4 changed files with 39 additions and 37 deletions

View File

@ -159,6 +159,7 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
}
std::uint64_t handle{};
{
std::shared_ptr<i_open_file> open_file;
if (is_create_op) {
const auto now = utils::get_file_time_now();
@ -170,7 +171,8 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
auto meta = create_meta_attributes(
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,
0U,
utils::path::combine(config_.get_cache_directory(),
{utils::create_uuid_string()}),
get_effective_uid(), now);
@ -183,6 +185,7 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
handle, open_file)) != api_error::success)) {
return res;
}
}
file_info->fh = handle;
if (is_truncate_op) {
@ -1242,8 +1245,9 @@ auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
return res;
}
open_file_data ofd{O_RDWR};
std::uint64_t handle{};
{
open_file_data ofd{O_RDWR};
std::shared_ptr<i_open_file> open_file;
if ((res = fm_->open(api_path, false, ofd, handle, open_file)) !=
api_error::success) {
@ -1251,8 +1255,8 @@ auto fuse_drive::truncate_impl(std::string api_path, off_t size) -> api_error {
}
res = open_file->resize(static_cast<std::uint64_t>(size));
}
fm_->close(handle);
return res;
}

View File

@ -137,7 +137,7 @@ void file_manager::close_timed_out_files() {
for (const auto &api_path : closeable_list) {
auto closeable_file = open_file_lookup_.at(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();
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 {
recur_mutex_lock open_lock(open_file_mtx_);
auto it = open_file_lookup_.find(api_path);
if (it != open_file_lookup_.end() && it->second->is_modified()) {
auto iter = open_file_lookup_.find(api_path);
if (iter != open_file_lookup_.end() && iter->second->is_modified()) {
return api_error::file_in_use;
}
@ -445,14 +445,13 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
return res;
}
remove_upload(api_path);
close_all(api_path);
if ((res = provider_.remove_file(api_path)) != api_error::success) {
return res;
}
remove_upload(api_path);
close_all(api_path);
if (not utils::file::retry_delete_file(fsi.source_path)) {
utils::error::raise_api_path_error(
__FUNCTION__, fsi.api_path, fsi.source_path,

View File

@ -233,6 +233,8 @@ auto file_manager::open_file_base::close() -> bool {
io_thread_.reset();
return true;
}
return false;
}
io_thread_notify_.notify_all();

View File

@ -519,15 +519,16 @@ static void test_xattr_removexattr(const std::string &file_path) {
TEST(fuse_drive, all_tests) {
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);
const auto test_directory =
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(
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));
{
std::unique_ptr<app_config> config_ptr{};
@ -536,7 +537,6 @@ TEST(fuse_drive, all_tests) {
const auto cfg_directory = utils::path::absolute(
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));
std::vector<std::string> drive_args{};
@ -704,9 +704,6 @@ TEST(fuse_drive, all_tests) {
drive_args.push_back(mount_location);
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);