From: Jordan Lee Date: Thu, 17 Jan 2013 18:55:51 +0000 (+0000) Subject: (utils) #4137 'support user-defined piece sizes in transmission-create' -- done.... X-Git-Tag: 2.80~270 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=447b558cdf1a86c867cd0291bf0accaf7786ce4c;p=transmission (utils) #4137 'support user-defined piece sizes in transmission-create' -- done. Initial patch by lav. --- diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index 78efaaf46..ad7a74ff8 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -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) { diff --git a/libtransmission/makemeta.h b/libtransmission/makemeta.h index 396ff4137..a54c244a9 100644 --- a/libtransmission/makemeta.h +++ b/libtransmission/makemeta.h @@ -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 diff --git a/utils/create.c b/utils/create.c index 9ce7217d1..bd0810961 100644 --- a/utils/create.c +++ b/utils/create.c @@ -11,9 +11,9 @@ */ #include -#include /* fprintf () */ -#include /* EXIT_FAILURE */ -#include /* getcwd () */ +#include /* fprintf() */ +#include /* strtoul(), EXIT_FAILURE */ +#include /* getcwd() */ #include #include @@ -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, "" }, + { 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", 1, "" }, { 'c', "comment", "Add a comment", "c", 1, "" }, { 't', "tracker", "Add a tracker's announce URL", "t", 1, "" }, { '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) { diff --git a/utils/transmission-create.1 b/utils/transmission-create.1 index d3dd38492..2a2de017d 100644 --- a/utils/transmission-create.1 +++ b/utils/transmission-create.1 @@ -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