Opened 11 years ago

Closed 11 years ago

#3562 closed Bug (fixed)

.torrent files are created incorrectly when the content is a single file inside a subdirectory

Reported by: nonzenze Owned by: charles
Priority: Normal Milestone: 2.10
Component: Transmission Version: 2.04
Severity: Blocker Keywords: create torrent
Cc: backport-2.0x

Description

When instructed to create a torrent from a directory containing a single file, Transmission creates a single file torrent from the contents. To confirm, I created a torrent from a directory containing a single file then ran it through bdecode and found that the 'info' directory did not contain the key 'files'.

I understand that this behavior is by design. I am requesting a UI element or preference setting (of the developer's chosing, hardly matters to me) to force the creation of a directory torrent containing only a single file. One the one hand, this is trivial. On the other, it should be wicked easy to implement. :-)

Change History (9)

comment:1 Changed 11 years ago by charles

This seems to bend the intent of the BT spec and could possibly cause confusion in other BitTorrent? clients' code.

What is the use case for using multi-file mode when generating a single file torrent?

comment:2 Changed 11 years ago by nonzenze

(1) The BT spec absolutely permits creating a multi-file mode containing a single path. The section "Info in Multiple File Mode" simply states that you create a entry for each file, not that there needs to be more than one.

(1A) Virtually every other client, when presented with a directory containing a single file, will create a multi-file-mode torrent containing a single path. Tranmission is aberrant (although not contrary to the spec) in this respect. Tested: uTorrent, Vuze, mktorrent, make_meta_file.py from the original BT python library released by Bram Cohen.

(1B) None of the above clients have a problem with a multi-file-mode torrent containing only a single path. Neither does Transmission, for that matter.

(2) The use case is that some private trackers forbid single-file torrents. Transmission users are then forced to either add a dummy second file or use another torrent client to create the metadata.

(3) Since this use case is relatively rare, I am not advocating for a change in default behavior. Only some manner of user control to allow Transmission users which of the two possible legal meta-files they want created.

comment:3 Changed 11 years ago by livings124

  • Component changed from Utils to Transmission
  • Version changed from 2.04+ to 2.04

comment:4 Changed 11 years ago by livings124

  • Priority changed from Low to Normal
  • Severity changed from Trivial to Normal
  • Type changed from Enhancement to Bug

This appears to be a bug. If I create a torrent from folder "Folder" with file "File" in it, it creates a single-file torrent with the data named "Folder". It should create a multi-file torrent with the directory name "Folder" but with a single data entry named "File".

comment:5 Changed 11 years ago by charles

  • Cc backport-2.0x added
  • Milestone changed from None Set to 2.10
  • Status changed from new to assigned

livings124 is right. We're using single-file-mode whenever there's a single file, even if it's inside a folder.

comment:6 Changed 11 years ago by charles

  • Resolution set to fixed
  • Status changed from assigned to closed
  • Summary changed from Force creation of a 'directory' torrent from a directory of one file to .torrent files are created incorrectly when the content is a single file inside a subdirectory

fixed in trunk by r11244

comment:7 Changed 11 years ago by Longinus00

  • Resolution fixed deleted
  • Severity changed from Normal to Blocker
  • Status changed from closed to reopened

Except now if you tell transmission to create a torrent that is only a single file by specifying the full path, like the gtk and qt guis do, it won't create a valid torrent.

$ cd /tmp
$ echo "test" > test
$ transmission-create test
WARNING: no trackers specified
Creating torrent "/tmp/test.torrent" .... done!
$ transmission-show test.torrent | grep -A5 FILES
FILES

  test (0.00 KiB)

$ transmission-create /tmp/test
WARNING: no trackers specified
Creating torrent "/tmp/test.torrent" .... done!
$ transmission-show test.torrent | grep -A5 FILES
FILES

  test/ (0.00 KiB)

Instead of checking if the filename starts with '/', makeInfoDict should be checking isSingleFile.

--- libtransmission/makemeta.c
+++ libtransmission/makemeta.c
@@ -336,11 +336,10 @@ makeInfoDict( tr_benc *             dict,
 {
     uint8_t * pch;
     char    * base;
-    const tr_bool single_file_mode = ( builder->fileCount == 1 ) && ( strchr( builder->files[0].filename, '/' ) == NULL );
 
     tr_bencDictReserve( dict, 5 );
 
-    if( single_file_mode )
+    if( builder->isSingleFile )
     {
         tr_bencDictAddInt( dict, "length", builder->files[0].size );
     }

comment:8 Changed 11 years ago by charles

Great catch. Please commit.

comment:9 Changed 11 years ago by Longinus00

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed by r11272.

Note: See TracTickets for help on using tickets.