fix saving fast resume on checking torrents

This commit is contained in:
Marcos Pinto 2008-01-19 04:53:36 +00:00
commit 263387c6c9

View file

@ -469,35 +469,30 @@ static PyObject *torrent_save_fastresume(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "is", &unique_ID, &torrent_name)) if (!PyArg_ParseTuple(args, "is", &unique_ID, &torrent_name))
return NULL; return NULL;
long index = get_index_from_unique_ID(unique_ID); try{
if (PyErr_Occurred()) long index = get_index_from_unique_ID(unique_ID);
return NULL; if (PyErr_Occurred())
return NULL;
torrent_handle& h = M_torrents->at(index).handle; torrent_handle& h = M_torrents->at(index).handle;
// For valid torrents, save fastresume data // For valid torrents, save fastresume data
if (h.is_valid() && h.has_metadata()) if (h.is_valid() && h.has_metadata())
{ {
h.pause(); entry data = h.write_resume_data();
std::stringstream s;
s << torrent_name << ".fastresume";
boost::filesystem::ofstream out(s.str(), std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), data);
entry data = h.write_resume_data(); }
}
std::stringstream s; catch(...){
s << torrent_name << ".fastresume"; printf("Fast resume saving failed\n");
}
boost::filesystem::ofstream out(s.str(), std::ios_base::binary); Py_INCREF(Py_None); return Py_None;
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), data);
h.resume();
Py_INCREF(Py_None); return Py_None;
} else
RAISE_PTR(DelugeError, "Invalid handle or no metadata for fastresume.");
} }
static PyObject *torrent_set_max_half_open(PyObject *self, PyObject *args) static PyObject *torrent_set_max_half_open(PyObject *self, PyObject *args)
{ {
python_long arg; python_long arg;