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
|
||||
if not isinstance(filedump, str):
|
||||
filedump = filedump.data
|
||||
|
||||
if len(filedump) == 0:
|
||||
log.warning("Torrent file is corrupt!")
|
||||
return
|
||||
|
||||
try:
|
||||
torrent_info = lt.torrent_info(lt.bdecode(filedump))
|
||||
except RuntimeError, e:
|
||||
log.warn("Unable to decode torrent file: %s", e)
|
||||
log.warning("Unable to decode torrent file: %s", e)
|
||||
return None
|
||||
|
||||
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):
|
||||
import deluge.libtorrent as lt
|
||||
import os.path
|
||||
new_row = None
|
||||
|
||||
for filename in filenames:
|
||||
# Get the torrent data from the torrent file
|
||||
try:
|
||||
log.debug("Attempting to open %s for add.", filename)
|
||||
_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()
|
||||
except IOError, e:
|
||||
log.warning("Unable to open %s: e", filename, e)
|
||||
continue
|
||||
|
||||
info = lt.torrent_info(filedump)
|
||||
try:
|
||||
info = lt.torrent_info(filedump)
|
||||
except RuntimeError, e:
|
||||
log.warning("Torrent appears to be corrupt!")
|
||||
continue
|
||||
|
||||
if str(info.info_hash()) in self.infos:
|
||||
log.debug("Torrent already in list!")
|
||||
return
|
||||
continue
|
||||
|
||||
# Get list of files from torrent info
|
||||
files = []
|
||||
|
@ -211,7 +220,7 @@ class AddTorrentDialog(component.Component):
|
|||
self.infos[str(info.info_hash())] = info
|
||||
|
||||
(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)
|
||||
|
||||
def _on_torrent_changed(self, treeselection):
|
||||
|
|
Loading…
Reference in New Issue