Changeset 13800


Ignore:
Timestamp:
Jan 17, 2013, 6:55:51 PM (8 years ago)
Author:
jordan
Message:

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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/makemeta.c

    r13683 r13800  
    163163           builderFileCompare);
    164164
    165     ret->pieceSize = bestPieceSize (ret->totalSize);
    166     ret->pieceCount = (int)(ret->totalSize / ret->pieceSize);
    167     if (ret->totalSize % ret->pieceSize)
    168         ++ret->pieceCount;
     165    tr_metaInfoBuilderSetPieceSize (ret, bestPieceSize (ret->totalSize));
    169166
    170167    return ret;
    171168}
     169
     170void
     171tr_metaInfoBuilderSetPieceSize (tr_metainfo_builder * b,
     172                                uint32_t              bytes)
     173{
     174  b->pieceSize = bytes;
     175
     176  b->pieceCount = (int)(b->totalSize / b->pieceSize);
     177  if (b->totalSize % b->pieceSize)
     178    ++b->pieceCount;
     179}
     180
    172181
    173182void
  • trunk/libtransmission/makemeta.h

    r13625 r13800  
    9292
    9393
    94 tr_metainfo_builder*tr_metaInfoBuilderCreate (const char * topFile);
     94tr_metainfo_builder * tr_metaInfoBuilderCreate (const char * topFile);
    9595
    96 void                tr_metaInfoBuilderFree (tr_metainfo_builder*);
     96/**
     97 * Call this before tr_makeMetaInfo() to override the builder.pieceSize
     98 * and builder.pieceCount values that were set by tr_metainfoBuilderCreate()
     99 */
     100void tr_metaInfoBuilderSetPieceSize (tr_metainfo_builder * builder,
     101                                     uint32_t              bytes);
     102
     103void tr_metaInfoBuilderFree (tr_metainfo_builder*);
    97104
    98105/**
  • trunk/utils/create.c

    r13625 r13800  
    1212
    1313#include <errno.h>
    14 #include <stdio.h> /* fprintf () */
    15 #include <stdlib.h> /* EXIT_FAILURE */
    16 #include <unistd.h> /* getcwd () */
     14#include <stdio.h> /* fprintf() */
     15#include <stdlib.h> /* strtoul(), EXIT_FAILURE */
     16#include <unistd.h> /* getcwd() */
    1717
    1818#include <libtransmission/transmission.h>
     
    2525
    2626#define MAX_TRACKERS 128
     27static const uint32_t KiB = 1024;
    2728static tr_tracker_info trackers[MAX_TRACKERS];
    2829static int trackerCount = 0;
    2930static bool isPrivate = false;
    3031static bool showVersion = false;
    31 const char * comment = NULL;
    32 const char * outfile = NULL;
    33 const char * infile = NULL;
     32static const char * comment = NULL;
     33static const char * outfile = NULL;
     34static const char * infile = NULL;
     35static uint32_t piecesize_kib = 0;
    3436
    3537static tr_option options[] =
     
    3739  { 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", 0, NULL },
    3840  { 'o', "outfile", "Save the generated .torrent to this filename", "o", 1, "<file>" },
     41  { 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", 1, "<size in KiB>" },
    3942  { 'c', "comment", "Add a comment", "c", 1, "<comment>" },
    4043  { 't', "tracker", "Add a tracker's announce URL", "t", 1, "<url>" },
     
    8184                trackers[trackerCount].announce = (char*) optarg;
    8285                  ++trackerCount;
     86              }
     87            break;
     88
     89          case 's':
     90            if (optarg)
     91              {
     92                char * endptr = NULL;
     93                piecesize_kib = strtoul (optarg, &endptr, 10);
     94                if (endptr && *endptr=='M')
     95                  piecesize_kib *= KiB;
    8396              }
    8497            break;
     
    170183
    171184  b = tr_metaInfoBuilderCreate (infile);
     185
     186  if (piecesize_kib != 0)
     187    tr_metaInfoBuilderSetPieceSize (b, piecesize_kib * KiB);
     188
    172189  tr_makeMetaInfo (b, outfile, trackers, trackerCount, comment, isPrivate);
    173190  while (!b->isDone)
  • trunk/utils/transmission-create.1

    r12376 r13800  
    1313.Op Fl c Ar comment
    1414.Op Fl t Ar tracker
     15.Op Fl s Ar piece-size-KiB
    1516.Op Ar source file or directory
    1617.Ek
     
    2829.It Fl c Fl -comment
    2930Add a comment to the torrent file.
     31.It Fl s Fl -piecesize
     32Set how many KiB each piece should be, overriding the preferred default
    3033.It Fl t Fl -tracker
    3134Add a tracker's
Note: See TracChangeset for help on using the changeset viewer.