refactor: constify the inout module (#6328)

* refactor: move tr_preallocation_mode info tr_open_files

* refactor: remove unnecessary error nullptr check

* refactor: use snake_case for private method names in inout.cc

* refactor: extract-method get_fd() from read_or_write_bytes()

* refactor: make function args const where possible

* refactor: simplify read_or_write_bytes()

* refactor: make buflen a uint64_t in read_or_write_piece()

* refactor: move tr_torrentStop() logic from read_or_write_piece() to tr_ioWrite()

* refactor: make tr_ioFoo() functions take a const torrent

* refactor: make tr_cache::close_torrent_files() take a tor_id instead of a torrent
This commit is contained in:
Charles Kerr
2023-12-02 14:16:36 -06:00
committed by GitHub
parent 9e7a860b57
commit 2e46bad22d
16 changed files with 226 additions and 240 deletions

View File

@@ -142,7 +142,7 @@ std::optional<tr_sys_file_t> tr_open_files::get(
tr_file_index_t file_num,
bool writable,
std::string_view filename_in,
tr_preallocation_mode allocation,
Preallocation allocation,
uint64_t file_size)
{
// is there already an entry
@@ -196,17 +196,17 @@ std::optional<tr_sys_file_t> tr_open_files::get(
return {};
}
if (writable && !already_existed && allocation != TR_PREALLOCATE_NONE)
if (writable && !already_existed && allocation != Preallocation::None)
{
bool success = false;
char const* type = nullptr;
if (allocation == TR_PREALLOCATE_FULL)
if (allocation == Preallocation::Full)
{
success = preallocate_file_full(fd, file_size, &error);
type = "full";
}
else if (allocation == TR_PREALLOCATE_SPARSE)
else if (allocation == Preallocation::Sparse)
{
success = preallocate_file_sparse(fd, file_size, &error);
type = "sparse";