Fix #300 do not crash when 0-byte .torrent file is added
This commit is contained in:
parent
409a824d7d
commit
c88fd0ab27
|
@ -355,10 +355,15 @@ class Core(
|
||||||
# Turn the filedump into a torrent_info
|
# Turn the filedump into a torrent_info
|
||||||
if not isinstance(filedump, str):
|
if not isinstance(filedump, str):
|
||||||
filedump = filedump.data
|
filedump = filedump.data
|
||||||
|
|
||||||
|
if len(filedump) == 0:
|
||||||
|
log.warning("Torrent file is corrupt!")
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
torrent_info = lt.torrent_info(lt.bdecode(filedump))
|
torrent_info = lt.torrent_info(lt.bdecode(filedump))
|
||||||
except RuntimeError, e:
|
except RuntimeError, e:
|
||||||
log.warn("Unable to decode torrent file: %s", e)
|
log.warning("Unable to decode torrent file: %s", e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
torrent_id = self.torrents.add(filedump=filedump, options=options, filename=filename)
|
torrent_id = self.torrents.add(filedump=filedump, options=options, filename=filename)
|
||||||
|
|
|
@ -177,23 +177,32 @@ class AddTorrentDialog(component.Component):
|
||||||
def add_from_files(self, filenames):
|
def add_from_files(self, filenames):
|
||||||
import deluge.libtorrent as lt
|
import deluge.libtorrent as lt
|
||||||
import os.path
|
import os.path
|
||||||
|
new_row = None
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
# Get the torrent data from the torrent file
|
# Get the torrent data from the torrent file
|
||||||
try:
|
try:
|
||||||
log.debug("Attempting to open %s for add.", filename)
|
log.debug("Attempting to open %s for add.", filename)
|
||||||
_file = open(filename, "rb")
|
_file = open(filename, "rb")
|
||||||
filedump = lt.bdecode(_file.read())
|
filedump = _file.read()
|
||||||
|
if not filedump:
|
||||||
|
log.warning("Torrent appears to be corrupt!")
|
||||||
|
continue
|
||||||
|
filedump = lt.bdecode(filedump)
|
||||||
_file.close()
|
_file.close()
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
log.warning("Unable to open %s: e", filename, e)
|
log.warning("Unable to open %s: e", filename, e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
info = lt.torrent_info(filedump)
|
info = lt.torrent_info(filedump)
|
||||||
|
except RuntimeError, e:
|
||||||
|
log.warning("Torrent appears to be corrupt!")
|
||||||
|
continue
|
||||||
|
|
||||||
if str(info.info_hash()) in self.infos:
|
if str(info.info_hash()) in self.infos:
|
||||||
log.debug("Torrent already in list!")
|
log.debug("Torrent already in list!")
|
||||||
return
|
continue
|
||||||
|
|
||||||
# Get list of files from torrent info
|
# Get list of files from torrent info
|
||||||
files = []
|
files = []
|
||||||
|
@ -211,7 +220,7 @@ class AddTorrentDialog(component.Component):
|
||||||
self.infos[str(info.info_hash())] = info
|
self.infos[str(info.info_hash())] = info
|
||||||
|
|
||||||
(model, row) = self.listview_torrents.get_selection().get_selected()
|
(model, row) = self.listview_torrents.get_selection().get_selected()
|
||||||
if row == None:
|
if not row and new_row:
|
||||||
self.listview_torrents.get_selection().select_iter(new_row)
|
self.listview_torrents.get_selection().select_iter(new_row)
|
||||||
|
|
||||||
def _on_torrent_changed(self, treeselection):
|
def _on_torrent_changed(self, treeselection):
|
||||||
|
|
Loading…
Reference in New Issue