]> granicus.if.org Git - transmission/commitdiff
Optionally include hidden files when creating a torrent gh305-improve-dotfiles
authorMike Gelfand <mikedld@mikedld.com>
Sun, 25 Mar 2018 13:08:04 +0000 (16:08 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Sun, 25 Mar 2018 13:08:04 +0000 (16:08 +0300)
Add support to transmission-create only for now. Not sure whether we will
need the same for GUI clients.

Fixes: #305
gtk/makemeta-ui.c
libtransmission/makemeta-test.c
libtransmission/makemeta.c
libtransmission/makemeta.h
macosx/CreatorWindowController.m
qt/MakeDialog.cc
utils/create.c
utils/transmission-create.1

index 7e01fcef687f3dddc2c4cdfb93599632908ab891..e98b3debebd7cb7a9be471e0fdd049d4ea9c2b4b 100644 (file)
@@ -330,7 +330,7 @@ static void setFilename(MakeMetaUI* ui, char const* filename)
 
     if (filename)
     {
-        ui->builder = tr_metaInfoBuilderCreate(filename);
+        ui->builder = tr_metaInfoBuilderCreate(filename, false);
     }
 
     updatePiecesLabel(ui);
index 610137813e994f55d713244d781f2a07e4b8dc88..3a6592832ba0a62f84c989a19fbd06d4324ba6b1 100644 (file)
@@ -34,7 +34,7 @@ static int test_single_file_impl(tr_tracker_info const* trackers, size_t const t
     /* create a single input file */
     input_file = tr_buildPath(sandbox, "test.XXXXXX", NULL);
     libtest_create_tmpfile_with_contents(input_file, payload, payloadSize);
-    builder = tr_metaInfoBuilderCreate(input_file);
+    builder = tr_metaInfoBuilderCreate(input_file, false);
     check_str(builder->top, ==, input_file);
     check_int(builder->fileCount, ==, 1);
     check_str(builder->files[0].filename, ==, input_file);
@@ -147,7 +147,7 @@ static int test_single_directory_impl(tr_tracker_info const* trackers, size_t co
     libttest_sync();
 
     /* init the builder */
-    builder = tr_metaInfoBuilderCreate(top);
+    builder = tr_metaInfoBuilderCreate(top, false);
     check(!builder->abortFlag);
     check_str(builder->top, ==, top);
     check_int(builder->fileCount, ==, payloadCount);
index 644a1f4ea681b3c2b13be156ccbfef0de7672b4b..8659e1aeea40c6a2ec31ef190e69de8701149324 100644 (file)
@@ -36,7 +36,7 @@ struct FileList
     struct FileList* next;
 };
 
-static struct FileList* getFiles(char const* dir, char const* base, struct FileList* list)
+static struct FileList* getFiles(char const* dir, char const* base, int readDirFlags, struct FileList* list)
 {
     if (dir == NULL || base == NULL)
     {
@@ -62,9 +62,9 @@ static struct FileList* getFiles(char const* dir, char const* base, struct FileL
     {
         char const* name;
 
-        while ((name = tr_sys_dir_read_name(odir, TR_SYS_DIR_READ_SKIP_HIDDEN, NULL)) != NULL)
+        while ((name = tr_sys_dir_read_name(odir, readDirFlags, NULL)) != NULL)
         {
-            list = getFiles(buf, name, list);
+            list = getFiles(buf, name, readDirFlags, list);
         }
 
         tr_sys_dir_close(odir, NULL);
@@ -129,7 +129,7 @@ static int builderFileCompare(void const* va, void const* vb)
     return evutil_ascii_strcasecmp(a->filename, b->filename);
 }
 
-tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFileArg)
+tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFileArg, bool includeHiddenFiles)
 {
     char* const real_top = tr_sys_path_resolve(topFileArg, NULL);
 
@@ -154,7 +154,10 @@ tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFileArg)
     {
         char* dir = tr_sys_path_dirname(ret->top, NULL);
         char* base = tr_sys_path_basename(ret->top, NULL);
-        files = getFiles(dir, base, NULL);
+        int const readDirFlags = includeHiddenFiles ? 0 : TR_SYS_DIR_READ_SKIP_HIDDEN;
+
+        files = getFiles(dir, base, readDirFlags, NULL);
+
         tr_free(base);
         tr_free(dir);
     }
index 4056769de58bbe8aab046b0bcdd5aef0f16e1966..760e2503ffc1d725bf512eb3b7d201a6072161b6 100644 (file)
@@ -85,7 +85,7 @@ typedef struct tr_metainfo_builder
 }
 tr_metainfo_builder;
 
-tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFile);
+tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFile, bool includeHiddenFiles);
 
 /**
  * Call this before tr_makeMetaInfo() to override the builder.pieceSize
index aa0f8af5005872bafc7dd43adac72b26179d10b0..7947e097237a138178f335d7a832e9b40be32498 100644 (file)
@@ -72,11 +72,11 @@ NSMutableSet *creatorWindowControllerSet = nil;
         if (!creatorWindowControllerSet) {
             creatorWindowControllerSet = [NSMutableSet set];
         }
-        
+
         fStarted = NO;
 
         fPath = path;
-        fInfo = tr_metaInfoBuilderCreate([[fPath path] UTF8String]);
+        fInfo = tr_metaInfoBuilderCreate([[fPath path] UTF8String], false);
 
         if (fInfo->fileCount == 0)
         {
@@ -133,7 +133,7 @@ NSMutableSet *creatorWindowControllerSet = nil;
             if (!tr_urlIsValidTracker([fTrackers[i] UTF8String]))
                 [fTrackers removeObjectAtIndex: i];
         }
-        
+
         [creatorWindowControllerSet addObject:self];
     }
     return self;
index 746c481af8304661ec6efb0f82668fca1561de75..f4d36f3f41bd16bbdb31aee8058e68cf3bb9228c 100644 (file)
@@ -207,7 +207,7 @@ void MakeDialog::onSourceChanged()
 
     if (!filename.isEmpty())
     {
-        myBuilder.reset(tr_metaInfoBuilderCreate(filename.toUtf8().constData()));
+        myBuilder.reset(tr_metaInfoBuilderCreate(filename.toUtf8().constData(), false));
     }
 
     QString text;
index 2b00dd81de60dc4f41e54504e71175a98f8df14b..eafe5673e9de960df26a70617ad756f9ff7afedb 100644 (file)
@@ -25,6 +25,7 @@
 static uint32_t const KiB = 1024;
 static tr_tracker_info trackers[MAX_TRACKERS];
 static int trackerCount = 0;
+static bool includeHiddenFiles = false;
 static bool isPrivate = false;
 static bool showVersion = false;
 static char const* comment = NULL;
@@ -39,6 +40,7 @@ static tr_option options[] =
     { '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>" },
+    { 'H', "include-hidden", "Include hidden files and directories into the torrent", "H", 0, NULL },
     { 'V', "version", "Show version number and exit", "V", 0, NULL },
     { 0, NULL, NULL, NULL, 0, NULL }
 };
@@ -65,6 +67,10 @@ static int parseCommandLine(int argc, char const* const* argv)
             isPrivate = true;
             break;
 
+        case 'H':
+            includeHiddenFiles = true;
+            break;
+
         case 'o':
             outfile = optarg;
             break;
@@ -190,7 +196,7 @@ int tr_main(int argc, char* argv[])
     printf("Creating torrent \"%s\" ...", outfile);
     fflush(stdout);
 
-    b = tr_metaInfoBuilderCreate(infile);
+    b = tr_metaInfoBuilderCreate(infile, includeHiddenFiles);
 
     if (b == NULL)
     {
index b0ee7a3fb302f31edbb6dfcaa6310f7b91ea3108..137c035c064e2494c033c9a031c54c166c172ea0 100644 (file)
@@ -9,6 +9,7 @@
 .Nm
 .Op Fl h
 .Op Fl p
+.Op Fl H
 .Op Fl o Ar file
 .Op Fl c Ar comment
 .Op Fl t Ar tracker
@@ -36,6 +37,11 @@ Add a tracker's
 to the .torrent. Most torrents will have at least one
 .Ar announce URL.
 To add more than one, use this option multiple times.
+.It Fl H Fl -include-hidden
+Include hidden files and directories into the torrent. The notion of "hidden"
+varies between platforms; on *NIX systems these are the files and directories
+having name starting with a dot (".") character, on Windows they will have a
+corresponding attribute set instead.
 .El
 .Sh AUTHORS
 .An -nosplit