mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-10 20:22:31 +00:00
* Fixed handling of errors when writing out session torrents, it should no longer hit an infinite loop.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1099 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -82,7 +82,10 @@ DownloadList::clear() {
|
||||
|
||||
void
|
||||
DownloadList::session_save() {
|
||||
std::for_each(begin(), end(), std::bind1st(std::mem_fun(&DownloadStore::save), control->core()->download_store()));
|
||||
unsigned int c = std::count_if(begin(), end(), std::bind1st(std::mem_fun(&DownloadStore::save), control->core()->download_store()));
|
||||
|
||||
if (c != size())
|
||||
control->core()->push_log("Failed to save session torrents.");
|
||||
|
||||
control->dht_manager()->save_dht_cache();
|
||||
}
|
||||
|
||||
@@ -98,20 +98,21 @@ DownloadStore::set_path(const std::string& path) {
|
||||
m_path = rak::path_expand(path);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
DownloadStore::save(Download* d) {
|
||||
if (!is_enabled())
|
||||
return;
|
||||
return true;
|
||||
|
||||
std::fstream f((create_filename(d) + ".new").c_str(), std::ios::out | std::ios::trunc);
|
||||
|
||||
if (!f.is_open())
|
||||
return;
|
||||
return false;
|
||||
|
||||
// Move this somewhere else?
|
||||
d->bencode()->get_key("rtorrent").insert_key("total_uploaded", d->download()->up_rate()->total());
|
||||
d->bencode()->get_key("rtorrent").insert_key("chunks_done", d->download()->file_list()->completed_chunks());
|
||||
|
||||
torrent::Object tmp;
|
||||
torrent::Object& resumeObject = d->download()->bencode()->get_key("libtorrent_resume");
|
||||
|
||||
torrent::resume_save_addresses(*d->download(), resumeObject);
|
||||
@@ -121,22 +122,26 @@ DownloadStore::save(Download* d) {
|
||||
f << *d->bencode();
|
||||
|
||||
if (!f.good())
|
||||
return;
|
||||
goto download_store_save_error;
|
||||
|
||||
f.close();
|
||||
|
||||
// Test the new file, to ensure it is a valid bencode string.
|
||||
f.open((create_filename(d) + ".new").c_str(), std::ios::in);
|
||||
|
||||
torrent::Object tmp;
|
||||
f >> tmp;
|
||||
|
||||
if (!f.good())
|
||||
return;
|
||||
goto download_store_save_error;
|
||||
|
||||
f.close();
|
||||
|
||||
::rename((create_filename(d) + ".new").c_str(), create_filename(d).c_str());
|
||||
return true;
|
||||
|
||||
download_store_save_error:
|
||||
f.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
const std::string& path() const { return m_path; }
|
||||
void set_path(const std::string& path);
|
||||
|
||||
void save(Download* d);
|
||||
bool save(Download* d);
|
||||
void remove(Download* d);
|
||||
|
||||
// Currently shows all entries in the correct format.
|
||||
|
||||
Reference in New Issue
Block a user