Compare commits
3 Commits
ac66240fac
...
88436c9d1f
Author | SHA1 | Date | |
---|---|---|---|
88436c9d1f | |||
b41699af5c | |||
6886f7d392 |
@ -78,6 +78,10 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
[[nodiscard]] static auto can_handle_file(std::uint64_t file_size,
|
||||
std::size_t chunk_size,
|
||||
std::size_t ring_size) -> bool;
|
||||
|
||||
auto close() -> bool override;
|
||||
|
||||
void forward(std::size_t count);
|
||||
|
@ -404,8 +404,18 @@ auto file_manager::open(
|
||||
}
|
||||
|
||||
if (not closeable_file) {
|
||||
const auto get_download_type = [this,
|
||||
&fsi](download_type type) -> download_type {
|
||||
auto buffer_directory =
|
||||
utils::path::combine(config_.get_data_directory(), {"buffer"});
|
||||
auto chunk_size =
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size();
|
||||
auto ring_size =
|
||||
(static_cast<std::uint64_t>(config_.get_ring_buffer_file_size() *
|
||||
1024UL * 1024UL) /
|
||||
chunk_size);
|
||||
|
||||
const auto get_download_type =
|
||||
[this, &buffer_directory, &chunk_size, &fsi,
|
||||
&ring_size](download_type type) -> download_type {
|
||||
if (fsi.size == 0U) {
|
||||
return download_type::fallback;
|
||||
}
|
||||
@ -422,8 +432,12 @@ auto file_manager::open(
|
||||
}
|
||||
}
|
||||
|
||||
auto free_space = utils::file::get_free_drive_space(
|
||||
utils::path::combine(config_.get_data_directory(), {"buffer"}));
|
||||
if (not ring_buffer_open_file::can_handle_file(fsi.size, chunk_size,
|
||||
ring_size)) {
|
||||
return download_type::direct;
|
||||
}
|
||||
|
||||
auto free_space = utils::file::get_free_drive_space(buffer_directory);
|
||||
if (config_.get_ring_buffer_file_size() < free_space) {
|
||||
return download_type::ring_buffer;
|
||||
}
|
||||
@ -437,27 +451,24 @@ auto file_manager::open(
|
||||
switch (get_download_type(config_.get_preferred_download_type())) {
|
||||
case repertory::download_type::direct: {
|
||||
closeable_file = std::make_shared<direct_open_file>(
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size(),
|
||||
chunk_timeout, fsi, provider_);
|
||||
chunk_size, chunk_timeout, fsi, provider_);
|
||||
} break;
|
||||
|
||||
case repertory::download_type::ring_buffer: {
|
||||
closeable_file = std::make_shared<ring_buffer_open_file>(
|
||||
utils::path::combine(config_.get_data_directory(), {"buffer"}),
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size(),
|
||||
chunk_timeout, fsi, provider_);
|
||||
buffer_directory, chunk_size, chunk_timeout, fsi, provider_,
|
||||
ring_size);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
closeable_file = std::make_shared<open_file>(
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size(),
|
||||
chunk_timeout, fsi, provider_, *this);
|
||||
closeable_file = std::make_shared<open_file>(chunk_size, chunk_timeout,
|
||||
fsi, provider_, *this);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
open_file_lookup_[api_path] = closeable_file;
|
||||
create_and_add_handle(closeable_file);
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ ring_buffer_open_file::ring_buffer_open_file(std::string buffer_directory,
|
||||
throw std::runtime_error("ring size must be greater than or equal to 4");
|
||||
}
|
||||
|
||||
if (fsi.size < (ring_state_.size() * chunk_size)) {
|
||||
if (not can_handle_file(fsi.size, chunk_size, ring_size)) {
|
||||
throw std::runtime_error("file size is less than ring buffer size");
|
||||
}
|
||||
|
||||
@ -103,6 +103,12 @@ ring_buffer_open_file::~ring_buffer_open_file() {
|
||||
}
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::can_handle_file(std::uint64_t file_size,
|
||||
std::size_t chunk_size,
|
||||
std::size_t ring_size) -> bool {
|
||||
return file_size <= (static_cast<std::uint64_t>(ring_size) * chunk_size);
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::close() -> bool {
|
||||
stop_requested_ = true;
|
||||
return open_file_base::close();
|
||||
|
Reference in New Issue
Block a user