From 62eef9133839eb49b81802d36d01d200bef27a78 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 11 Apr 2010 21:02:43 +0000 Subject: [PATCH] added setting to ignore file modification time when loading resume files --- ChangeLog | 1 + docs/manual.rst | 10 ++++++++++ include/libtorrent/session_settings.hpp | 7 +++++++ src/session_impl.cpp | 1 + src/storage.cpp | 25 ++++++++++++++++++------- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8714ba8dc..c780deb36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * added setting to ignore file modification time when loading resume files * support more fine-grained torrent states between which peer sources it announces to * supports calculating sha1 file-hashes when creating torrents diff --git a/docs/manual.rst b/docs/manual.rst index 1d8e1e89e..058bafcc6 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3872,6 +3872,7 @@ session_settings int default_peer_upload_rate; int default_peer_download_rate; bool broadcast_lsd; + bool ignore_resume_timestamps; }; ``user_agent`` this is the client identification to the tracker. @@ -4503,6 +4504,15 @@ if ``broadcast_lsd`` is set to true, the local peer discovery broadcast its messages. This can be useful when running on networks that don't support multicast. It's off by default since it's inefficient. +``ignore_resume_timestamps`` determines if the storage, when loading +resume data files, should verify that the file modification time +with the timestamps in the resume data. This defaults to false, which +means timestamps are taken into account, and resume data is less likely +to accepted (torrents are more likely to be fully checked when loaded). +It might be useful to set this to true if your network is faster than your +disk, and it would be faster to redownload potentially missed pieces than +to go through the whole storage to look for them. + pe_settings =========== diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 676dfb4fa..14146a6cd 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -211,6 +211,7 @@ namespace libtorrent , default_peer_upload_rate(0) , default_peer_download_rate(0) , broadcast_lsd(false) + , ignore_resume_timestamps(false) {} // this is the user agent that will be sent to the tracker @@ -810,6 +811,12 @@ namespace libtorrent // default in order to avoid flooding networks for no good reason. If // a network is known not to support multicast, this can be enabled bool broadcast_lsd; + + // when set to true, the file modification time is ignored when loading + // resume data. The resume data includes the expected timestamp of each + // file and is typically compared to make sure the files haven't changed + // since the last session + bool ignore_resume_timestamps; }; #ifndef TORRENT_DISABLE_DHT diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 3a3db44fb..9ee6fadf2 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -306,6 +306,7 @@ namespace aux { TORRENT_SETTING(boolean, strict_end_game_mode) TORRENT_SETTING(integer, default_peer_upload_rate) TORRENT_SETTING(integer, default_peer_download_rate) + TORRENT_SETTING(boolean, ignore_resume_timestamps) }; #undef TORRENT_SETTING diff --git a/src/storage.cpp b/src/storage.cpp index 2785ba4d6..1a06f3fb4 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -187,11 +187,17 @@ namespace libtorrent // resume data. This is because full allocation will not move // pieces, so any older version of the resume data will // still be a correct subset of the actual data on disk. + enum flags_t + { + compact_mode = 1, + ignore_timestamps = 2 + }; + bool match_filesizes( file_storage const& fs , std::string p , std::vector > const& sizes - , bool compact_mode + , int flags , error_code& error) { if ((int)sizes.size() != fs.num_files()) @@ -220,17 +226,20 @@ namespace libtorrent time = s.mtime; } - if ((compact_mode && size != size_iter->first) - || (!compact_mode && size < size_iter->first)) + if (((flags & compact_mode) && size != size_iter->first) + || (!(flags & compact_mode) && size < size_iter->first)) { error = errors::mismatching_file_size; return false; } + + if (flags & ignore_timestamps) continue; + // allow one second 'slack', because of FAT volumes // in sparse mode, allow the files to be more recent // than the resume data, but only by 5 minutes - if ((compact_mode && (time > size_iter->second + 1 || time < size_iter->second - 1)) || - (!compact_mode && (time > size_iter->second + 5 * 60 || time < size_iter->second - 1))) + if (((flags & compact_mode) && (time > size_iter->second + 1 || time < size_iter->second - 1)) || + (!(flags & compact_mode) && (time > size_iter->second + 5 * 60 || time < size_iter->second - 1))) { error = errors::mismatching_file_timestamp; return false; @@ -823,8 +832,10 @@ namespace libtorrent } } } - return match_filesizes(files(), m_save_path, file_sizes - , !full_allocation_mode, error); + int flags = (full_allocation_mode ? 0 : compact_mode) + | (settings().ignore_resume_timestamps ? ignore_timestamps : 0); + + return match_filesizes(files(), m_save_path, file_sizes, flags, error); }