idlesign / torrentool

The tool to work with torrent files.
https://github.com/idlesign/torrentool
BSD 3-Clause "New" or "Revised" License
148 stars 30 forks source link

IndexError on creating torrent from an empty file #11

Closed Lumen-git closed 4 years ago

Lumen-git commented 4 years ago

using the line myTorrent = Torrent.create_from(activeFile) with activeFile = C:/Users/user/Desktop/test/file2.txt returns:

File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\torrentool\torrent.py", line 410, in create_from info['length'] = target_files[0][1] IndexError: list index out of range

idlesign commented 4 years ago

Unfortunatelly I do not use Windows, and can be little of help. First check the supplied path is correct (I expect to see backslashes on Windows ). To investigate it further you may want to set a breakpoint on line 410 and see what's in target_files.

Lumen-git commented 4 years ago

Windows can recognize either slash in a path. Running through the debugger, target_files becomes an empty list by the time the program hits line 357 in torrent.py

idlesign commented 4 years ago

Check whether file is empty. Empty files are skipped.

Lumen-git commented 4 years ago

That'd be it. What's the move for not having it crash the whole program on an empty file? A try/except?

idlesign commented 4 years ago

We probably need to handle IndexError on line 410.

There're two ways:

  1. Just ignore it. But that would probably produce an invalid torrent file (we'll need to check that using come torrent client, e.g. Transmission).
  2. Wrap it into TorrentError with a more user friendly description, like "Unable to create a torrent for empty file."

The 2nd seems to me more appropriate. If so, yes, try/except is to be used.

idlesign commented 4 years ago

Since 1.1.0 TorrentError is raised with a more proper description.

Considered closed. Feel free to reopen if required.