From ebc2ba35b578cf7241852fafddd42993e2713d94 Mon Sep 17 00:00:00 2001 From: "Alexander V. Lukyanov" Date: Mon, 12 Sep 2016 10:25:54 +0300 Subject: [PATCH] MirrorJob: new option --directory (-F) to mirror top directories by glob pattern. --- src/MirrorJob.cc | 21 +++++++++++++++------ src/MirrorJob.h | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/MirrorJob.cc b/src/MirrorJob.cc index 3f25941..5ba40a0 100644 --- a/src/MirrorJob.cc +++ b/src/MirrorJob.cc @@ -753,7 +753,7 @@ void MirrorJob::HandleListInfoCreation(const FileAccessRef& session,SMTaskRef
  • FollowSymlinks(); - list_info->SetExclude(relative_dir,exclude); + list_info->SetExclude(relative_dir,top_exclude?top_exclude:exclude); list_info->Roll(); } @@ -1722,6 +1722,7 @@ CMD(mirror) {"verbose",optional_argument,0,'v'}, {"newer-than",required_argument,0,'N'}, {"file",required_argument,0,'f'}, + {"directory",required_argument,0,'F'}, {"older-than",required_argument,0,OPT_OLDER_THAN}, {"size-range",required_argument,0,OPT_SIZE_RANGE}, {"dereference",no_argument,0,'L'}, @@ -1786,6 +1787,7 @@ CMD(mirror) const char *recursion_mode=0; Ref exclude; + Ref top_exclude; if(!ResMgr::QueryBool("mirror:set-permissions",0)) flags|=MirrorJob::NO_PERMS; @@ -1798,7 +1800,7 @@ CMD(mirror) const char *target_dir=NULL; args->rewind(); - while((opt=args->getopt_long("esi:x:I:X:nrpcRvN:LP:af:O:",mirror_opts,0))!=EOF) + while((opt=args->getopt_long("esi:x:I:X:nrpcRvN:LP:af:F:O:",mirror_opts,0))!=EOF) { switch(opt) { @@ -1875,11 +1877,17 @@ CMD(mirror) case('N'): newer_than=optarg; break; - case('f'): - { - // mirror for a single file (or glob pattern). + case('f'): // mirror for a single file (or glob pattern). recursion_mode="never"; - MirrorJob::AddPattern(exclude,'I',basename_ptr(optarg)); + /*fallthrough*/ + case('F'): // mirror for a single directory (or glob pattern). + { + xstring pattern(basename_ptr(optarg)); + if(opt=='F' && pattern.last_char()!='/') + pattern.append('/'); + if(!top_exclude) + top_exclude=new PatternSet(); + top_exclude->Add(PatternSet::INCLUDE,new PatternSet::Glob(pattern)); source_dir=dirname(optarg); source_dir=alloca_strdup(source_dir); // save the temp string break; @@ -2106,6 +2114,7 @@ CMD(mirror) j->SetFlags(flags,1); j->SetVerbose(verbose); j->SetExclude(exclude.borrow()); + j->SetTopExclude(top_exclude.borrow()); if(newer_than) j->SetNewerThan(newer_than); diff --git a/src/MirrorJob.h b/src/MirrorJob.h index a3da287..a9a0df8 100644 --- a/src/MirrorJob.h +++ b/src/MirrorJob.h @@ -138,6 +138,7 @@ class MirrorJob : public Job recursion_mode_t recursion_mode; int max_error_count; + Ref top_exclude; Ref my_exclude; const PatternSet *exclude; @@ -249,6 +250,7 @@ class MirrorJob : public Job void SetExclude(const PatternSet *x) { exclude=x; } void SetSizeRange(Range *r) { my_size_range=r; size_range=my_size_range; } void SetSizeRange(const Range *r) { size_range=r; } + void SetTopExclude(PatternSet *x) { top_exclude=x; } void SetVerbose(int v) { verbose_report=v; }