]> granicus.if.org Git - transmission/commitdiff
(utils) #4137 'support user-defined piece sizes in transmission-create' -- done....
authorJordan Lee <jordan@transmissionbt.com>
Thu, 17 Jan 2013 18:55:51 +0000 (18:55 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Thu, 17 Jan 2013 18:55:51 +0000 (18:55 +0000)
libtransmission/makemeta.c
libtransmission/makemeta.h
utils/create.c
utils/transmission-create.1

index 78efaaf46c6b695ddc82e223cb687ff72b2f817d..ad7a74ff8107b5abf6422a815e395691c158ec3e 100644 (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)
 {
index 396ff4137bba9c3d990b03144e214318412d880b..a54c244a9d1ec8c3eebcfbabb0fee557b6eb4ea6 100644 (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
index 9ce7217d198bac379eb689787043fdfc54209055..bd0810961b8820fab83ef802c19db86d0cbd8d0a 100644 (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>
 #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)
     {
index d3dd3849297e88e01c36dbbb8e5a84e980398c4f..2a2de017d676c5c248ec516f2446b77d5e74ef66 100644 (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