Re: [libtorrent] patch to save and restore save_path to/from fastresume files
Brought to you by:
arvidn
|
From: Andrew E. <an...@sk...> - 2014-06-06 21:36:24
|
Looks good to me. Thanks for reviewing it so quickly.
On Jun 6, 2014, at 13:19, arvid <ar...@cs...> wrote:
> On 2014-06-06 10:24, Andrew Evans wrote:
>> This patch adds save_path to the fastresume data when resume data is
>> saved, and restores the fastresume data to the torrent on resume. This
>> solves the problem of libtorrent not knowing where the files were
>> saved if e.g. different save_path's are used for seeding vs.
>> downloading vs. completed downloads. It seems to be working well for
>> me.
>
> How about this one? (essentially to support overriding it in add_torrent_params).
>
> Index: src/torrent.cpp
> ===================================================================
> --- src/torrent.cpp (revision 9987)
> +++ src/torrent.cpp (working copy)
> @@ -1487,6 +1487,17 @@
> return;
> }
>
> + // Chicken-and-egg: need to load resume data to get last save_path
> + // before constructing m_owning_storage, but need storage before
> + // loading resume data. So peek ahead in this case.
> + // only do this if the user is willing to have the resume data
> + // settings override the settings set in add_torrent_params
> + if (!m_override_resume_data && m_resume_entry.type() == lazy_entry::dict_t)
> + {
> + std::string p = m_resume_entry.dict_find_string_value("save_path");
> + if (!p.empty()) m_save_path = p;
> + }
> +
> // the shared_from_this() will create an intentional
> // cycle of ownership, se the hpp file for description.
> m_owning_storage = new piece_manager(shared_from_this(), m_torrent_file
> @@ -5196,6 +5207,12 @@
> m_last_download = rd.dict_find_int_value("last_download", 0);
> m_last_upload = rd.dict_find_int_value("last_upload", 0);
>
> + if (!m_override_resume_data)
> + {
> + std::string p = rd.dict_find_string_value("save_path");
> + if (!p.empty()) m_save_path = p;
> + }
> +
> m_url = rd.dict_find_string_value("url");
> m_uuid = rd.dict_find_string_value("uuid");
> m_source_feed_url = rd.dict_find_string_value("feed");
> @@ -5395,6 +5412,8 @@
> ret["last_download"] = m_last_download;
> ret["last_upload"] = m_last_upload;
>
> + ret["save_path"] = m_save_path;
> +
> if (!m_url.empty()) ret["url"] = m_url;
> if (!m_uuid.empty()) ret["uuid"] = m_uuid;
> if (!m_source_feed_url.empty()) ret["feed"] = m_source_feed_url;
> @@ -6675,6 +6694,8 @@
>
> m_save_path = save_path;
> #endif
> + m_need_save_resume_data = true;
> +
> if (alerts().should_post<storage_moved_alert>())
> {
> alerts().post_alert(storage_moved_alert(get_handle(), m_save_path));
> @@ -6693,6 +6714,7 @@
> if (alerts().should_post<storage_moved_alert>())
> alerts().post_alert(storage_moved_alert(get_handle(), j.str));
> m_save_path = j.str;
> + m_need_save_resume_data = true;
> if (ret == piece_manager::need_full_check)
> force_recheck();
> }
>
> --
> Arvid Norberg
|