| 1 | #!/usr/local/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | my $VERSION = $File::Value::VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use Getopt::Long qw(:config bundling_override); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use File::Value ':all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | my %opt = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | force => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | help => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | lshigh => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | lslow => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | man => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | mknext => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | mknextcopy => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | version => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | verbose => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # main | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 17 | ▶ | GetOptions(\%opt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 'force|f', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'help|h|?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'lshigh', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'lslow', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 'man', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'mknext', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'mknextcopy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'verbose|v', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ) or pod2usage(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | help(), exit(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 17 | ▶ | if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | pod2usage(-exitstatus => 0, -verbose => 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 17 | ▶ | if $opt{man}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | print "$VERSION\n" and exit(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 17 | ▶ | if $opt{version}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$opt{'version'} && (print("$VERSION\n") && exit 0)
print "$VERSION\n" and exit 0
MC/DC0%0/2
$opt{'version'} && (print("$VERSION\n") && exit 0)
$opt{'version'}
print "$VERSION\n"
Truth table33%1/3
A && B
A= $opt{'version'}B= print "$VERSION\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | pod2usage("$0: --mknext cannot be given with --lshigh or --lslow") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 17 | ▶ | if ($opt{lshigh} || $opt{lslow}) && $opt{mknext}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$opt{"lshigh"} || $opt{"lslow"} and $opt{"mknext"}
$opt{"lshigh"} or $opt{"lslow"}
MC/DC0%0/3
$opt{"lshigh"} || $opt{"lslow"} and $opt{"mknext"}
$opt{"lshigh"}
$opt{"lslow"}
$opt{"mknext"}
Truth table60%3/5
A or B and C
A= $opt{"lshigh"}B= $opt{"lslow"}C= $opt{"mknext"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 17 | ▶ | help(), exit(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | #pod2usage("$0: no file or directory names given") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | unless @ARGV; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 17 | foreach my $node (@ARGV) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 17 | my $as_dir = ($node =~ s,/+$,,); # a dir if ends in '/' | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 17 | ▶ | my $prnode = $node # print-friendly name | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | . ($as_dir ? '/' : ''); # has '/' added back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 17 | my ($n, $msg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 17 | ▶ | if ($opt{lshigh} or $opt{lslow}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$opt{"lshigh"} or $opt{"lslow"}
MC/DC100%2/2
$opt{"lshigh"} or $opt{"lslow"}
$opt{"lshigh"}
$opt{"lslow"}
Truth table100%3/3
A or B
A= $opt{"lshigh"}B= $opt{"lslow"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # we're only asked to report either or both of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # the low version and the high version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | my @nodes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | $node =~ s/\d+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | if ($opt{lslow}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ($n, $msg) = list_low_version($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | $n == -1 and print(STDERR | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | "$prnode: has no numbered versions\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | exit 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | push @nodes, $msg; # got it, $msg is node | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | if ($opt{lshigh}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ($n, $msg) = list_high_version($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | $n == -1 and print(STDERR | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | "$prnode: has no numbered versions\n"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | exit 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | push @nodes, $msg; # got it, $msg is node | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | print join(" ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | grep { (-d $_ and s,$,/,) or $_ } @nodes), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
-d $_ && s[$][/] || $_
-d $_ and s[$][/]
MC/DC0%0/3
-d $_ && s[$][/] || $_
-d $_
s[$][/]
$_
Truth table20%1/5
A and B || C
A= -d $_B= s[$][/]C= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # yyy support "missing" versions ?? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ▶ | elsif ($opt{mknext} or $opt{mknextcopy}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opt{"mknext"} or $opt{"mknextcopy"}
MC/DC100%2/2
$opt{"mknext"} or $opt{"mknextcopy"}
$opt{"mknext"}
$opt{"mknextcopy"}
Truth table100%3/3
A or B
A= $opt{"mknext"}B= $opt{"mknextcopy"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ($n, $msg) = snag_version($node, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | as_dir => $as_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | no_type_mismatch => ! $opt{force}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | mknextcopy => $opt{mknextcopy}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 10 | ▶ | if ($n == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | print STDERR "$prnode: $msg\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | exit 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # got it: $msg is the node name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 7 | ▶ | print "$msg", ($as_dir ? '/' : ''), "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 7 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | else { # simple snag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 5 | ▶ | if ($opt{force} && -e $node) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt{"force"} and -e $node
MC/DC50%1/2
$opt{"force"} and -e $node
$opt{"force"}
-e $node
Truth table66%2/3
A and B
A= $opt{"force"}B= -e $node
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | -d $node and | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition30%3/10
-d $node && (rmdir $node || die("${node}: $!")) || (unlink($node) || die("${node}: $!"))
-d $node and rmdir $node || die("${node}: $!")
rmdir $node or die "${node}: $!"
unlink $node or die "${node}: $!"
MC/DC0%0/3
-d $node && (rmdir $node || die("${node}: $!")) || (unlink($node) || die("${node}: $!"))
-d $node
rmdir $node
unlink $node
Truth table20%1/5
A and B || C
A= -d $nodeB= rmdir $nodeC= unlink $node
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | rmdir($node) || die "$node: $!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | unlink($node) || die "$node: $!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | ▶ | $msg = $as_dir ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | snag_dir($node) : snag_file($node); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | ▶ | if ($msg eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | print "$prnode\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | ▶ | if ($msg eq '1') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | print "$prnode already exists"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | print ", but as a ", ($as_dir ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | "file" : "directory") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | if ($as_dir != -d $node); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | print STDERR "$prnode: $msg\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | exit 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 13 | exit 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | print << 'EOI'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | snag - capture, without clobbering, a file or directory version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | Basic usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | snag <name> if <name> doesn't exist, create as a file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | snag <name>/ if <name> doesn't exist, create as a directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | Version-aware usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | snag --lshigh <name>[/] list highest existing version of <name> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | snag --lslow <name>[/] list lowest existing version of <name> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | snag --mknext <name>[/] create next highest unused version of <name> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | snag --mknextcopy <name> like --mknext (files only) followed by a copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | A version number is just a terminal digit string in <name> (default "1"). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | That string's value becomes the next version number if no numbered versions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | exist, and its length is the minimum width of the next version number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | string. See "snag --man" for full documentation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | EOI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||