fix open file data
This commit is contained in:
@ -82,6 +82,9 @@ public:
|
|||||||
|
|
||||||
virtual void set_api_path(const std::string &api_path) = 0;
|
virtual void set_api_path(const std::string &api_path) = 0;
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
set_open_data(std::map<std::uint64_t, open_file_data> open_data) = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual auto write(std::uint64_t write_offset,
|
[[nodiscard]] virtual auto write(std::uint64_t write_offset,
|
||||||
const data_buffer &data,
|
const data_buffer &data,
|
||||||
std::size_t &bytes_written) -> api_error = 0;
|
std::size_t &bytes_written) -> api_error = 0;
|
||||||
|
@ -178,9 +178,7 @@ public:
|
|||||||
return fsi_.source_path;
|
return fsi_.source_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto has_handle(std::uint64_t handle) const -> bool override {
|
[[nodiscard]] auto has_handle(std::uint64_t handle) const -> bool override;
|
||||||
return open_data_.find(handle) != open_data_.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto is_directory() const -> bool override {
|
[[nodiscard]] auto is_directory() const -> bool override {
|
||||||
return fsi_.directory;
|
return fsi_.directory;
|
||||||
@ -193,6 +191,9 @@ public:
|
|||||||
void remove_all() override;
|
void remove_all() override;
|
||||||
|
|
||||||
void set_api_path(const std::string &api_path) override;
|
void set_api_path(const std::string &api_path) override;
|
||||||
|
|
||||||
|
void
|
||||||
|
set_open_data(std::map<std::uint64_t, open_file_data> open_data) override;
|
||||||
};
|
};
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ public:
|
|||||||
[[nodiscard]] auto read(std::size_t read_size, std::uint64_t read_offset,
|
[[nodiscard]] auto read(std::size_t read_size, std::uint64_t read_offset,
|
||||||
data_buffer &data) -> api_error override;
|
data_buffer &data) -> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto resize(std::uint64_t) -> api_error override {
|
[[nodiscard]] auto resize(std::uint64_t /* size */) -> api_error override {
|
||||||
return api_error::not_supported;
|
return api_error::not_supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,6 +259,7 @@ auto file_manager::get_open_file(std::uint64_t handle, bool write_supported,
|
|||||||
: 0U,
|
: 0U,
|
||||||
file_ptr->get_filesystem_item(), file_ptr->get_open_data(), provider_,
|
file_ptr->get_filesystem_item(), file_ptr->get_open_data(), provider_,
|
||||||
*this);
|
*this);
|
||||||
|
writeable_file->set_open_data(file_ptr->get_open_data());
|
||||||
open_file_lookup_[file_ptr->get_api_path()] = writeable_file;
|
open_file_lookup_[file_ptr->get_api_path()] = writeable_file;
|
||||||
file = writeable_file;
|
file = writeable_file;
|
||||||
return true;
|
return true;
|
||||||
|
@ -127,8 +127,8 @@ auto open_file_base::can_close() const -> bool {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::chrono::system_clock::time_point last_access = last_access_;
|
std::chrono::system_clock::time_point last_access{last_access_};
|
||||||
const auto duration = std::chrono::duration_cast<std::chrono::seconds>(
|
auto duration = std::chrono::duration_cast<std::chrono::seconds>(
|
||||||
std::chrono::system_clock::now() - last_access);
|
std::chrono::system_clock::now() - last_access);
|
||||||
return (duration.count() >= chunk_timeout_);
|
return (duration.count() >= chunk_timeout_);
|
||||||
}
|
}
|
||||||
@ -198,6 +198,7 @@ auto open_file_base::get_filesystem_item() const -> filesystem_item {
|
|||||||
|
|
||||||
auto open_file_base::get_handles() const -> std::vector<std::uint64_t> {
|
auto open_file_base::get_handles() const -> std::vector<std::uint64_t> {
|
||||||
recur_mutex_lock file_lock(file_mtx_);
|
recur_mutex_lock file_lock(file_mtx_);
|
||||||
|
|
||||||
std::vector<std::uint64_t> ret;
|
std::vector<std::uint64_t> ret;
|
||||||
for (const auto &item : open_data_) {
|
for (const auto &item : open_data_) {
|
||||||
ret.emplace_back(item.first);
|
ret.emplace_back(item.first);
|
||||||
@ -234,6 +235,11 @@ auto open_file_base::get_open_file_count() const -> std::size_t {
|
|||||||
return open_data_.size();
|
return open_data_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto open_file_base::has_handle(std::uint64_t handle) const -> bool {
|
||||||
|
recur_mutex_lock file_lock(file_mtx_);
|
||||||
|
return open_data_.find(handle) != open_data_.end();
|
||||||
|
}
|
||||||
|
|
||||||
auto open_file_base::is_modified() const -> bool {
|
auto open_file_base::is_modified() const -> bool {
|
||||||
recur_mutex_lock file_lock(file_mtx_);
|
recur_mutex_lock file_lock(file_mtx_);
|
||||||
return modified_;
|
return modified_;
|
||||||
@ -297,6 +303,12 @@ void open_file_base::set_api_path(const std::string &api_path) {
|
|||||||
fsi_.api_parent = utils::path::get_parent_api_path(api_path);
|
fsi_.api_parent = utils::path::get_parent_api_path(api_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void open_file_base::set_open_data(
|
||||||
|
std::map<std::uint64_t, open_file_data> open_data) {
|
||||||
|
recur_mutex_lock file_lock(file_mtx_);
|
||||||
|
open_data_ = std::move(open_data);
|
||||||
|
}
|
||||||
|
|
||||||
auto open_file_base::close() -> bool {
|
auto open_file_base::close() -> bool {
|
||||||
unique_mutex_lock io_lock(io_thread_mtx_);
|
unique_mutex_lock io_lock(io_thread_mtx_);
|
||||||
if (io_stop_requested_ || not io_thread_) {
|
if (io_stop_requested_ || not io_thread_) {
|
||||||
|
@ -102,6 +102,10 @@ public:
|
|||||||
MOCK_METHOD(void, remove, (std::uint64_t handle), (override));
|
MOCK_METHOD(void, remove, (std::uint64_t handle), (override));
|
||||||
|
|
||||||
MOCK_METHOD(void, remove_all, (), (override));
|
MOCK_METHOD(void, remove_all, (), (override));
|
||||||
|
|
||||||
|
MOCK_METHOD(void, set_open_data,
|
||||||
|
((std::map<std::uint64_t, open_file_data> open_data)),
|
||||||
|
(override));
|
||||||
};
|
};
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user