1 From ebc2ba35b578cf7241852fafddd42993e2713d94 Mon Sep 17 00:00:00 2001
2 From: "Alexander V. Lukyanov" <lavv17f@gmail.com>
3 Date: Mon, 12 Sep 2016 10:25:54 +0300
4 Subject: [PATCH] MirrorJob: new option --directory (-F) to mirror top
5 directories by glob pattern.
8 src/MirrorJob.cc | 21 +++++++++++++++------
10 2 files changed, 17 insertions(+), 6 deletions(-)
12 diff --git a/src/MirrorJob.cc b/src/MirrorJob.cc
13 index 3f25941..5ba40a0 100644
14 --- a/src/MirrorJob.cc
15 +++ b/src/MirrorJob.cc
16 @@ -753,7 +753,7 @@ void MirrorJob::HandleListInfoCreation(const FileAccessRef& session,SMTaskRef<Li
17 if(flags&RETR_SYMLINKS)
18 list_info->FollowSymlinks();
20 - list_info->SetExclude(relative_dir,exclude);
21 + list_info->SetExclude(relative_dir,top_exclude?top_exclude:exclude);
25 @@ -1722,6 +1722,7 @@ CMD(mirror)
26 {"verbose",optional_argument,0,'v'},
27 {"newer-than",required_argument,0,'N'},
28 {"file",required_argument,0,'f'},
29 + {"directory",required_argument,0,'F'},
30 {"older-than",required_argument,0,OPT_OLDER_THAN},
31 {"size-range",required_argument,0,OPT_SIZE_RANGE},
32 {"dereference",no_argument,0,'L'},
33 @@ -1786,6 +1787,7 @@ CMD(mirror)
34 const char *recursion_mode=0;
36 Ref<PatternSet> exclude;
37 + Ref<PatternSet> top_exclude;
39 if(!ResMgr::QueryBool("mirror:set-permissions",0))
40 flags|=MirrorJob::NO_PERMS;
41 @@ -1798,7 +1800,7 @@ CMD(mirror)
42 const char *target_dir=NULL;
45 - while((opt=args->getopt_long("esi:x:I:X:nrpcRvN:LP:af:O:",mirror_opts,0))!=EOF)
46 + while((opt=args->getopt_long("esi:x:I:X:nrpcRvN:LP:af:F:O:",mirror_opts,0))!=EOF)
50 @@ -1875,11 +1877,17 @@ CMD(mirror)
56 - // mirror for a single file (or glob pattern).
57 + case('f'): // mirror for a single file (or glob pattern).
58 recursion_mode="never";
59 - MirrorJob::AddPattern(exclude,'I',basename_ptr(optarg));
61 + case('F'): // mirror for a single directory (or glob pattern).
63 + xstring pattern(basename_ptr(optarg));
64 + if(opt=='F' && pattern.last_char()!='/')
65 + pattern.append('/');
67 + top_exclude=new PatternSet();
68 + top_exclude->Add(PatternSet::INCLUDE,new PatternSet::Glob(pattern));
69 source_dir=dirname(optarg);
70 source_dir=alloca_strdup(source_dir); // save the temp string
72 @@ -2106,6 +2114,7 @@ CMD(mirror)
74 j->SetVerbose(verbose);
75 j->SetExclude(exclude.borrow());
76 + j->SetTopExclude(top_exclude.borrow());
79 j->SetNewerThan(newer_than);
80 diff --git a/src/MirrorJob.h b/src/MirrorJob.h
81 index a3da287..a9a0df8 100644
84 @@ -138,6 +138,7 @@ class MirrorJob : public Job
85 recursion_mode_t recursion_mode;
88 + Ref<PatternSet> top_exclude;
89 Ref<PatternSet> my_exclude;
90 const PatternSet *exclude;
92 @@ -249,6 +250,7 @@ class MirrorJob : public Job
93 void SetExclude(const PatternSet *x) { exclude=x; }
94 void SetSizeRange(Range *r) { my_size_range=r; size_range=my_size_range; }
95 void SetSizeRange(const Range *r) { size_range=r; }
96 + void SetTopExclude(PatternSet *x) { top_exclude=x; }
98 void SetVerbose(int v) { verbose_report=v; }