diff --git a/src/core/download_list.cc b/src/core/download_list.cc index 9bffabf5..551f8732 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -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(); } diff --git a/src/core/download_store.cc b/src/core/download_store.cc index 4fb6a3b0..17dd4b04 100644 --- a/src/core/download_store.cc +++ b/src/core/download_store.cc @@ -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 diff --git a/src/core/download_store.h b/src/core/download_store.h index 42bd76a5..70d60625 100644 --- a/src/core/download_store.h +++ b/src/core/download_store.h @@ -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.