From 8d991b4ce5da720fe53c7ae47965fc4784aef695 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Fri, 28 Mar 2025 15:24:34 +0100 Subject: [PATCH] Added 'system.files.session.fdatasync' config option. --- .gitignore | 3 +-- src/command_local.cc | 1 + src/command_ui.cc | 28 ++++++++++++++-------------- src/core/download_store.cc | 11 +++++++---- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 901b7963..391be7f9 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,5 @@ TAGS # rTorrent specific files ########################### src/rtorrent -test/rtorrentTest +test/rtorrent_Test* test-driver -test/rtorrentTest.trs diff --git a/src/command_local.cc b/src/command_local.cc index c3b28623..fa46e544 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -222,6 +222,7 @@ initialize_command_local() { CMD2_ANY ("system.files.advise_random", std::bind(&FM_t::advise_random, fileManager)); CMD2_ANY_VALUE_V ("system.files.advise_random.set", std::bind(&FM_t::set_advise_random, fileManager, std::placeholders::_2)); + CMD2_VAR_BOOL ("system.files.session.fdatasync", true); CMD2_ANY ("system.files.opened_counter", std::bind(&FM_t::files_opened_counter, fileManager)); CMD2_ANY ("system.files.closed_counter", std::bind(&FM_t::files_closed_counter, fileManager)); diff --git a/src/command_ui.cc b/src/command_ui.cc index 1eebc23c..86f99b29 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -28,7 +28,7 @@ apply_view_filter_on(const torrent::Object::list_type& args) { throw torrent::input_error("Too few arguments."); const std::string& name = args.front().as_string(); - + if (name.empty()) throw torrent::input_error("First argument must be a string."); @@ -99,7 +99,7 @@ apply_view_set(const torrent::Object::list_type& args) { } torrent::Object -apply_print(rpc::target_type target, const torrent::Object& rawArgs) { +apply_print([[maybe_unused]] rpc::target_type target, const torrent::Object& rawArgs) { char buffer[1024]; rpc::print_object(buffer, buffer + 1024, &rawArgs, 0); @@ -108,7 +108,7 @@ apply_print(rpc::target_type target, const torrent::Object& rawArgs) { } torrent::Object -apply_cat(rpc::target_type target, const torrent::Object& rawArgs) { +apply_cat([[maybe_unused]] rpc::target_type target, const torrent::Object& rawArgs) { std::string result; rpc::print_object_std(&result, &rawArgs, 0); @@ -116,7 +116,7 @@ apply_cat(rpc::target_type target, const torrent::Object& rawArgs) { } torrent::Object -apply_value(rpc::target_type target, const torrent::Object::list_type& args) { +apply_value([[maybe_unused]] rpc::target_type target, const torrent::Object::list_type& args) { if (args.size() < 1) throw torrent::input_error("'value' takes at least a number argument!"); if (args.size() > 2) @@ -184,7 +184,7 @@ apply_not(rpc::target_type target, const torrent::Object& rawArgs) { } torrent::Object -apply_false(rpc::target_type target, const torrent::Object& rawArgs) { +apply_false([[maybe_unused]] rpc::target_type target, [[maybe_unused]] const torrent::Object& rawArgs) { return (int64_t)0; } @@ -199,10 +199,10 @@ apply_and(rpc::target_type target, const torrent::Object& rawArgs) { return (int64_t)false; } else if (itr->is_value()) { - if (!itr->as_value()) + if (!itr->as_value()) return (int64_t)false; - } else { + } else { // TODO: Switch to new versions that only accept the new command syntax. if (!as_boolean(rpc::parse_command_single(target, itr->as_string()))) return (int64_t)false; @@ -222,10 +222,10 @@ apply_or(rpc::target_type target, const torrent::Object& rawArgs) { return (int64_t)true; } else if (itr->is_value()) { - if (itr->as_value()) + if (itr->as_value()) return (int64_t)true; - } else { + } else { if (as_boolean(rpc::parse_command_single(target, itr->as_string()))) return (int64_t)true; } @@ -262,7 +262,7 @@ apply_cmp(rpc::target_type target, const torrent::Object::list_type& args) { if (result1.type() != result2.type()) throw torrent::input_error("Type mismatch."); - + switch (result1.type()) { case torrent::Object::TYPE_VALUE: return result1.as_value() - result2.as_value(); case torrent::Object::TYPE_STRING: return result1.as_string().compare(result2.as_string()); @@ -391,7 +391,7 @@ apply_to_time(const torrent::Object& rawArgs, int flags) { u = std::localtime(&t); else u = std::gmtime(&t); - + if (u == NULL) return torrent::Object(); @@ -434,7 +434,7 @@ apply_to_mb(const torrent::Object& rawArgs) { torrent::Object apply_to_xb(const torrent::Object& rawArgs) { char buffer[48]; - int64_t arg = rawArgs.as_value(); + int64_t arg = rawArgs.as_value(); if (arg < (int64_t(1000) << 10)) snprintf(buffer, 48, "%5.1f KB", (double)arg / (int64_t(1) << 10)); @@ -450,7 +450,7 @@ apply_to_xb(const torrent::Object& rawArgs) { torrent::Object apply_to_throttle(const torrent::Object& rawArgs) { - int64_t arg = rawArgs.as_value(); + int64_t arg = rawArgs.as_value(); if (arg < 0) return "---"; else if (arg == 0) @@ -548,7 +548,7 @@ cmd_view_size_not_visible(const torrent::Object::string_type& args) { torrent::Object cmd_view_persistent(const torrent::Object::string_type& args) { core::View* view = *control->view_manager()->find_throw(args); - + if (!view->get_filter().is_empty() || !view->event_added().is_empty() || !view->event_removed().is_empty()) throw torrent::input_error("Cannot set modified views as persitent."); diff --git a/src/core/download_store.cc b/src/core/download_store.cc index ccf8196c..006e4b5d 100644 --- a/src/core/download_store.cc +++ b/src/core/download_store.cc @@ -20,6 +20,7 @@ #include "download.h" #include "download_store.h" +#include "rpc/parse_commands.h" namespace core { @@ -93,12 +94,14 @@ DownloadStore::write_bencode(const std::string& filename, const torrent::Object& if (fd < 0) goto download_store_save_error; + if (rpc::call_command_value("system.files.session.fdatasync")) { #ifdef __APPLE__ - fsync(fd); + fsync(fd); #else - fdatasync(fd); + fdatasync(fd); #endif - ::close(fd); + ::close(fd); + } return true; @@ -141,7 +144,7 @@ DownloadStore::save(Download* d, int flags) { ::rename((base_filename + ".libtorrent_resume.new").c_str(), (base_filename + ".libtorrent_resume").c_str()); ::rename((base_filename + ".rtorrent.new").c_str(), (base_filename + ".rtorrent").c_str()); - + if (!(flags & flag_skip_static) && write_bencode(base_filename + ".new", *d->bencode(), torrent::Object::flag_session_data)) ::rename((base_filename + ".new").c_str(), base_filename.c_str());