(utils) #4137 'support user-defined piece sizes in transmission-create' -- done. Initial patch by lav.

This commit is contained in:
Jordan Lee
2013-01-17 18:55:51 +00:00
parent 9d6db0da15
commit 447b558cdf
4 changed files with 48 additions and 12 deletions
+13 -4
View File
@@ -162,14 +162,23 @@ tr_metaInfoBuilderCreate (const char * topFileArg)
sizeof (tr_metainfo_builder_file),
builderFileCompare);
ret->pieceSize = bestPieceSize (ret->totalSize);
ret->pieceCount = (int)(ret->totalSize / ret->pieceSize);
if (ret->totalSize % ret->pieceSize)
++ret->pieceCount;
tr_metaInfoBuilderSetPieceSize (ret, bestPieceSize (ret->totalSize));
return ret;
}
void
tr_metaInfoBuilderSetPieceSize (tr_metainfo_builder * b,
uint32_t bytes)
{
b->pieceSize = bytes;
b->pieceCount = (int)(b->totalSize / b->pieceSize);
if (b->totalSize % b->pieceSize)
++b->pieceCount;
}
void
tr_metaInfoBuilderFree (tr_metainfo_builder * builder)
{
+9 -2
View File
@@ -91,9 +91,16 @@ typedef struct tr_metainfo_builder
tr_metainfo_builder;
tr_metainfo_builder*tr_metaInfoBuilderCreate (const char * topFile);
tr_metainfo_builder * tr_metaInfoBuilderCreate (const char * topFile);
void tr_metaInfoBuilderFree (tr_metainfo_builder*);
/**
* Call this before tr_makeMetaInfo() to override the builder.pieceSize
* and builder.pieceCount values that were set by tr_metainfoBuilderCreate()
*/
void tr_metaInfoBuilderSetPieceSize (tr_metainfo_builder * builder,
uint32_t bytes);
void tr_metaInfoBuilderFree (tr_metainfo_builder*);
/**
* @brief create a new .torrent file
+23 -6
View File
@@ -11,9 +11,9 @@
*/
#include <errno.h>
#include <stdio.h> /* fprintf () */
#include <stdlib.h> /* EXIT_FAILURE */
#include <unistd.h> /* getcwd () */
#include <stdio.h> /* fprintf() */
#include <stdlib.h> /* strtoul(), EXIT_FAILURE */
#include <unistd.h> /* getcwd() */
#include <libtransmission/transmission.h>
#include <libtransmission/makemeta.h>
@@ -24,18 +24,21 @@
#define MY_NAME "transmission-create"
#define MAX_TRACKERS 128
static const uint32_t KiB = 1024;
static tr_tracker_info trackers[MAX_TRACKERS];
static int trackerCount = 0;
static bool isPrivate = false;
static bool showVersion = false;
const char * comment = NULL;
const char * outfile = NULL;
const char * infile = NULL;
static const char * comment = NULL;
static const char * outfile = NULL;
static const char * infile = NULL;
static uint32_t piecesize_kib = 0;
static tr_option options[] =
{
{ 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", 0, NULL },
{ 'o', "outfile", "Save the generated .torrent to this filename", "o", 1, "<file>" },
{ 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", 1, "<size in KiB>" },
{ 'c', "comment", "Add a comment", "c", 1, "<comment>" },
{ 't', "tracker", "Add a tracker's announce URL", "t", 1, "<url>" },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
@@ -83,6 +86,16 @@ parseCommandLine (int argc, const char ** argv)
}
break;
case 's':
if (optarg)
{
char * endptr = NULL;
piecesize_kib = strtoul (optarg, &endptr, 10);
if (endptr && *endptr=='M')
piecesize_kib *= KiB;
}
break;
case TR_OPT_UNK:
infile = optarg;
break;
@@ -169,6 +182,10 @@ main (int argc, char * argv[])
fflush (stdout);
b = tr_metaInfoBuilderCreate (infile);
if (piecesize_kib != 0)
tr_metaInfoBuilderSetPieceSize (b, piecesize_kib * KiB);
tr_makeMetaInfo (b, outfile, trackers, trackerCount, comment, isPrivate);
while (!b->isDone)
{
+3
View File
@@ -12,6 +12,7 @@
.Op Fl o Ar file
.Op Fl c Ar comment
.Op Fl t Ar tracker
.Op Fl s Ar piece-size-KiB
.Op Ar source file or directory
.Ek
.Sh DESCRIPTION
@@ -27,6 +28,8 @@ Save the generated .torrent to this filename.
Flag the torrent as intended for use on private trackers.
.It Fl c Fl -comment
Add a comment to the torrent file.
.It Fl s Fl -piecesize
Set how many KiB each piece should be, overriding the preferred default
.It Fl t Fl -tracker
Add a tracker's
.Ar announce URL