From 25f05d318b48d235ae9886e29ce1ff677fb3d36f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 3 Jul 2023 00:43:07 +0000 Subject: dtas-archive: support -m/--match=REGEXP switch Sometimes I only want to archive files matching a certain regexp pattern. --- Documentation/dtas-archive.pod | 11 ++++++++++- bin/dtas-archive | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Documentation/dtas-archive.pod b/Documentation/dtas-archive.pod index 157ea70..50237e8 100644 --- a/Documentation/dtas-archive.pod +++ b/Documentation/dtas-archive.pod @@ -52,11 +52,20 @@ Continue after error Number of times to repeat the L check. Default: 1 +=item -m, --match REGEX + +Only archive files matching a given Ruby (or Perl-compatible) regular +expression. The regular expression is implementation-dependent and +using the Perl-compatible subset of Ruby regexps is recommended as dtas +will be moving away from Ruby at some point. + +Added for dtas v0.22.0 + =back =head1 COPYRIGHT -Copyright 2013-2020 all contributors L +Copyright all contributors L License: GPL-3.0+ L diff --git a/bin/dtas-archive b/bin/dtas-archive index c88873e..7c0e4f7 100755 --- a/bin/dtas-archive +++ b/bin/dtas-archive @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -# Copyright (C) 2015-2020 all contributors +# Copyright (C) all contributors # License: GPL-3.0+ # frozen_string_literal: true usage = "#$0 SOURCE DESTINATION" @@ -30,6 +30,7 @@ stats = false keep_going = false compression = [] comment = [] +match = nil OptionParser.new('', 24, ' ') do |op| op.banner = usage @@ -47,6 +48,7 @@ OptionParser.new('', 24, ' ') do |op| op.on('-r', '--repeat [COUNT]', 'number of times to check', Integer) do |r| repeat = r end + op.on('-m', '--match=REGEX', String) { |s| match = Regexp.new(s) } op.on('-s', '--quiet', '--silent') { silent = true } op.on('-h', '--help') do puts(op.to_s) @@ -55,6 +57,7 @@ OptionParser.new('', 24, ' ') do |op| op.parse!(ARGV) end +match ||= %r/./ comment.push('--comment', '') if comment.empty? dst = ARGV.pop @@ -67,6 +70,7 @@ src.each do |s| src_st = File.stat(s) if src_st.directory? Find.find(s) do |path| + path =~ match or next File.file?(path) or next dir = File.dirname(path) dir_st = File.stat(dir) -- cgit v1.2.3-24-ge0c7