* 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:
rakshasa
2009-10-23 15:45:45 +00:00
parent 6c3a80636a
commit f11c48d454
3 changed files with 16 additions and 8 deletions
+4 -1
View File
@@ -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();
}
+11 -6
View File
@@ -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
+1 -1
View File
@@ -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.