about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-07-03 00:43:07 +0000
committerEric Wong <e@80x24.org>2023-07-03 02:06:54 +0000
commit25f05d318b48d235ae9886e29ce1ff677fb3d36f (patch)
tree95fdff40d674b20bbb4cf544bea4f112c7be6f99
parent02d3d1856fb9d9d41cf1711b9ad877b520a721e6 (diff)
downloaddtas-25f05d318b48d235ae9886e29ce1ff677fb3d36f.tar.gz
Sometimes I only want to archive files matching a certain regexp pattern.
-rw-r--r--Documentation/dtas-archive.pod11
-rwxr-xr-xbin/dtas-archive6
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<sndfile-cmp(1)> 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<mailto:dtas-all@nongnu.org>
+Copyright all contributors L<mailto:dtas-all@nongnu.org>
 
 License: GPL-3.0+ L<https://www.gnu.org/licenses/gpl-3.0.txt>
 
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 <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # 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)