mpetazzoni / ttorrent

BitTorrent Java library with tracker and download client
http://mpetazzoni.github.com/ttorrent/
Apache License 2.0
1.38k stars 502 forks source link

Currupted .torrent file created if directory contains no files #233

Closed mbait closed 5 years ago

mbait commented 5 years ago

To reproduce create a .torrent file with the means of ttorrent (TorrentCreator or TorrentMetadataBuilder), that has at least one nested directory, so that the layout is:

root-directory
└── sub-directory
    └── any-arbitrary-file (can be empty)

In that case my .torrent file contained root-directory as if it had been a file rather than a directory. Below are what Transmission shows when the generated .torrent files are opened with it:

data
└── BINANCE
    └── .empty

broken

data
├── BINANCE
│   └── .empty
└── .empty

normal

Dead-off commented 5 years ago

does library work correctly in second case? I don't see some problems there.

In first case you create one file. Library detects it and creates single-file torrent (https://wiki.theory.org/index.php/BitTorrentSpecification#Info_in_Single_File_Mode). This mode doesn't support directories. You can override this behaviour. Specify root directory name via setDirectoryName method. Then library will create multi-file torrent always. (but there was a bug. I fixed it. update library:) )

result code for first case:

new MetadataBuilder()
            .setDirectoryName("data")
            .addDataSource(new ByteArrayInputStream(new byte[]{1, 2}), "BINANCE/.empty", true)
            .buildBinary()

qbittorrent client opens created .torrent file correctly

mbait commented 5 years ago

Yes, the library worked correctly in the second case, I included it to show the discrepancy between the two generated files. To make it clear, in both cases (single file torrent and multiple files torrent) I called setDirectoryName() and in both cases I expected the generated torrent file to preserve the directory structure. The problem was that in the single file torrent case the generated torrent file contained only one file at the root whose name was the value that I passed to setDirectoryName(). If you fixed that, then feel free to close the issue.

Dead-off commented 5 years ago

yes, it's fixed, thanks you!