From: Mike Gelfand Date: Sun, 25 Mar 2018 13:08:04 +0000 (+0300) Subject: Optionally include hidden files when creating a torrent X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=refs%2Fheads%2Fgh305-improve-dotfiles;p=transmission Optionally include hidden files when creating a torrent Add support to transmission-create only for now. Not sure whether we will need the same for GUI clients. Fixes: #305 --- diff --git a/gtk/makemeta-ui.c b/gtk/makemeta-ui.c index 7e01fcef6..e98b3debe 100644 --- a/gtk/makemeta-ui.c +++ b/gtk/makemeta-ui.c @@ -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); diff --git a/libtransmission/makemeta-test.c b/libtransmission/makemeta-test.c index 610137813..3a6592832 100644 --- a/libtransmission/makemeta-test.c +++ b/libtransmission/makemeta-test.c @@ -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); diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index 644a1f4ea..8659e1aee 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -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); } diff --git a/libtransmission/makemeta.h b/libtransmission/makemeta.h index 4056769de..760e2503f 100644 --- a/libtransmission/makemeta.h +++ b/libtransmission/makemeta.h @@ -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 diff --git a/macosx/CreatorWindowController.m b/macosx/CreatorWindowController.m index aa0f8af50..7947e0972 100644 --- a/macosx/CreatorWindowController.m +++ b/macosx/CreatorWindowController.m @@ -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; diff --git a/qt/MakeDialog.cc b/qt/MakeDialog.cc index 746c481af..f4d36f3f4 100644 --- a/qt/MakeDialog.cc +++ b/qt/MakeDialog.cc @@ -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; diff --git a/utils/create.c b/utils/create.c index 2b00dd81d..eafe5673e 100644 --- a/utils/create.c +++ b/utils/create.c @@ -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, "" }, { 'c', "comment", "Add a comment", "c", 1, "" }, { 't', "tracker", "Add a tracker's announce URL", "t", 1, "" }, + { '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) { diff --git a/utils/transmission-create.1 b/utils/transmission-create.1 index b0ee7a3fb..137c035c0 100644 --- a/utils/transmission-create.1 +++ b/utils/transmission-create.1 @@ -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