| 1 | # To do: change default behavior and add options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # snag foo -> defaults to: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # --mknextcopy for file if it exists, else snag_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # --mknext for dir if it exists, else snag_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # add options: --noversion, --dir (default is 'file'), --nocopy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Add list of regexs and substitutions for versions, esp. so that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # after foo.txt comes foo_1.txt instead of foo.txt_1; order is preference: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # qr/[-_]?(\d+)(\.[a-z]*)?$/, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # also check for case of foo_\d{4,6} which is a date be prepared to use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # today's date for next version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | package File::Value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 20 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 20 | our $VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 20 | $VERSION = sprintf "%d.%02d", q$Name: Release-1-02 $ =~ /Release-(\d+)-(\d+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 20 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 20 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 20 | our @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 20 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | file_value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | flvl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | list_high_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | list_low_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | snag_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | snag_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | snag_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | fiso_dname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | fiso_uname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 20 | our %EXPORT_TAGS = (all => [ @EXPORT_OK ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # if length is 0, go for it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 20 | my $ridiculous = 4294967296; # max length is 2**32 yyy a better way? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # returns empty string on success, else error message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 19 | ▶ | sub file_value { my( $file, $value, $how, $length )=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file_value: called CC=30 SCAR=34.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 19 | my $ret_value = \$_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 19 | ▶ | $file or return "must specify a file name"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # Force caller to be explicit about whether doing read/write/append. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 19 | ▶ | $file !~ /^\s*(<|>|>>)\s*(\S.*)/ and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | return "file ($file) must begin with '<', '>', or '>>'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 18 | my ($mode, $statfname) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 18 | ▶ | $how ||= "trim"; # trim (def), raw, untaint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$how ||= "trim"
MC/DC100%1/1
$how ||= "trim"
$how
Truth table100%2/2
A
A= $how
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 18 | $how = lc($how); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 18 | ▶ | $how ne "trim" && $how ne "raw" && $how ne "untaint" and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$how ne "trim" and $how ne "raw" and $how ne "untaint"
$how ne "trim" and $how ne "raw"
MC/DC100%3/3
$how ne "trim" and $how ne "raw" and $how ne "untaint"
$how ne "trim"
$how ne "raw"
$how ne "untaint"
Truth table100%4/4
A and B and C
A= $how ne "trim"B= $how ne "raw"C= $how ne "untaint"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | return "third arg ($how) must be one of: trim, raw, or untaint"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 17 | ▶ | if ($mode =~ />>?/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # If we get here, we're doing value-to-file case (> or >>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # ignore $how and $length, but we need specified $value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | ▶ | defined($value) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | return "needs a value to put in '$file'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # for $how, here we only understand "trim" or "raw", but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # "trim" removes initial and final \n, adding one final \n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 5 | ▶ | if ($how eq "trim") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | $value =~ s/^\s+//s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | $value =~ s/\s+$/\n/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | ▶ | open(OUT, $file) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | return "$statfname: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | my $r = print OUT $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | close(OUT); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | return ($r ? "" : "write failed: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # If we get here, we're doing file-to-value case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 12 | ▶ | my $go_for_it = (defined($length) && $length eq "0" ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $length and $length eq 0
MC/DC100%2/2
defined $length and $length eq 0
defined $length
$length eq 0
Truth table100%3/3
A and B
A= defined $lengthB= $length eq 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 12 | my $statlength = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 12 | ▶ | if (defined($length)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | $length !~ /^\d+$/ and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | return "length unspecified or not an integer"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | elsif ($statfname ne "-") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # yyy tested with "-" (stdin or stdout)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # no length means read whole file, but be reasonable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 9 | $statlength = (-s $statfname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 9 | ▶ | ! defined($statlength) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | return "$statfname: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 9 | ▶ | $length = ($statlength > $ridiculous | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ? $ridiculous : $statlength); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $length = $ridiculous; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 12 | ▶ | open(IN, $file) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | return "$statfname: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 12 | ▶ | if ($go_for_it) { # don't be reasonable about length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | $$ret_value = <IN>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | close(IN); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 11 | my ($offset, $n) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Ask for the whole $length but be prepared not to get it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 11 | ▶ | 1 while ($n = read(IN, $$ret_value, $length, $offset)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$n = read(IN, $$ret_value, $length, $offset) and $n > 0 and ($offset += $n) < $length
$n = read(IN, $$ret_value, $length, $offset) and $n > 0
MC/DC66%2/3
$n = read(IN, $$ret_value, $length, $offset) and $n > 0 and ($offset += $n) < $length
$n = read(IN, $$ret_value, $length, $offset)
$n > 0
($offset += $n) < $length
Truth table75%3/4
A and B and C
A= $n = read(IN, $$ret_value, $length, $offset)B= $n > 0C= ($offset += $n) < $length
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # yyy and print("offset=$offset\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | and $n > 0 and ($offset += $n) < $length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 11 | close(IN); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 11 | ▶ | ! defined($n) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | return "$statfname: failed to read $length bytes: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 11 | ▶ | return "$statfname: read fewer bytes than expected" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $statlength and $offset < $statlength
MC/DC0%0/2
defined $statlength and $offset < $statlength
defined $statlength
$offset < $statlength
Truth table66%2/3
A and B
A= defined $statlengthB= $offset < $statlength
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | if (defined($statlength) && $offset < $statlength); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | #if (defined($statlength) && $n < $statlength); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 12 | ▶ | if ($how eq "trim") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 8 | $$ret_value =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 8 | $$ret_value =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | elsif ($how eq "untaint") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | if ($$ret_value =~ /([-\@\w.]+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | $$ret_value = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # elsif ($how eq "raw") { then no further processing } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 12 | return ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Faster simpler cruder version of file_value(), just in case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub flvl { my( $file, $value )=@_; # $file must begin with >, <, or >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flvl: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ($file =~ /^\s*>>?/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | open(OUT, $file) or return "$file: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $r = print OUT $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | close(OUT); return ($r ? '' : "write failed: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # If we get here, we're doing file-to-value case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | open(IN, $file) or return "$file: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | local $/; $_[1] = <IN>; # slurp mode (entire file) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | close(IN); return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 20 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 20 | our $Win; # whether we're running on Windows | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 20 | ▶ | defined($Win) or # if we're on a Windows platform avoid -l | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | $Win = grep(/Win32|OS2/i, @File::Spec::ISA); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 20 | our ($B, $C); # short names for boundary char for output (B) and regexes (C) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | #our $B = $Win ? '\\\\' : '/'; # short name for boundary (\) in regexes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 20 | ▶ | $Win and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$File::Value::Win and $File::Value::B = "\\", $File::Value::C = $File::Value::B . $File::Value::B, 1
MC/DC0%0/2
$File::Value::Win and $File::Value::B = "\\", $File::Value::C = $File::Value::B . $File::Value::B, 1
$File::Value::Win
$File::Value::B = "\\", $File::Value::C = $File::Value::B . $File::Value::B, 1
Truth table33%1/3
A and B
A= $File::Value::WinB= $File::Value::B = "\\", $File::Value::C = $File::Value::B . $File::Value::B, 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | $B = '\\', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | $C = $B.$B, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | $B = $C = '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | #$B = '\\'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | #$C = $B.$B; # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Return the full normalized name of a filesystem-based object that can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # legitimately be specified either by its enclosing directory name or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # by the directory name plus something in that directory. Useful when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # a user could correctly say 'myobj' or 'myobj/minter.bdb' but we will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # eventually need the longer form to test existence or create the object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # It's important (eg, find_minder) that existence of enclosing directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # not be mistaken for existence of the object, since creating that dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # by itself (eg, with 'snag') could be a good way of reserving the minder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # that you are _about_ to create. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # Need this when the user will be specifying the location of an object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # that's defined by both an enclosing directory $base and a well-known | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # file or directory $last under $base. It is valid for the user to say | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # either $base/$last or $base, but an existence test against $base/$last | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # is what we need to perform to verify whether it's a legitimate object, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # with some tedious special cases when $base is '/' or '.'. Typical use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # cases: user specifies "pairtree_root", "ptname", "ptname/pairtree_root", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # "mintername/", or "mintername/minter.bdb". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # Lengthen base path with last component according to the table, normalizing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # multiple slashes between $base and $last. Useful to get tedious details | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # right and when path may already have the last component on it (in which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # case we don't want it there twice). Removes final slashes from $last. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # $base $last Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # 1. / bar /bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # 2. . bar bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # 3. foo bar foo/bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # 4. foo/ bar foo/bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # 5. foo/bar bar foo/bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # 6. bar bar bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # 7. "" bar bar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # 8. foo "" foo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # yyy might not port to Windows for the root directory cases | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # yyy was called prep_file in pt script | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # FISO = FIle System Object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # dname = "down" name (full name with descender, suitable for -X tests) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # uname = "up" name (upper name without descender, still unique, suitable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # for communicating with users) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 14 | ▶ | sub fiso_dname { my( $base, $last )=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fiso_dname: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 14 | ▶ | return (($base || "") . ($last || "")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%7/7
$base and $last
$base || ''
$last || ''
MC/DC100%2/2
$base and $last
$base
$last
MC/DC100%1/1
$base || ''
$base
MC/DC100%1/1
$last || ''
$last
Truth table100%3/3
A and B
A= $baseB= $last
Truth table100%2/2
A
A= $base
Truth table100%2/2
A
A= $last
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | unless ($base and $last); # cases 7-8 done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 12 | $last =~ s{${C}*(.*)${C}*$}{$1}o; # remove bounding slashes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 12 | ▶ | return "${B}$last" if $base =~ m{^${C}+$}o; # case 1 done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 9 | $base =~ s{${C}+$}{}o; # remove trailing slashes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 9 | ▶ | return "$last" if $base =~ m{^\.${C}*$}o; # case 2 done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 7 | ▶ | return "$base${B}$last" if $base !~ m{$last$}; # cases 3-4 gone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | ▶ | return "$last" if $base =~ m{^$last$}; # case 6 eliminated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | $base =~ s{${C}*$last$}{}; # remove $last and preceding slashes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | return "$base${B}$last"; # case 5 done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # Return parent of $oname (object name) with trailing slash intact. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # xxx This needs to work closely with fiso_dname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 8 | ▶ | sub fiso_uname { my( $oname )=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fiso_uname: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 8 | ▶ | return "" unless $oname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 6 | ▶ | return "${B}" if $oname =~ m,^${C}+$,o; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | ▶ | return ".${B}" if $oname =~ m,^\.${C}*$,o; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # next assumes $oname was a directory? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # final / means this fiso_dname was a dir? yyy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | $oname =~ s,[^${C}]+${C}*$,,o; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 4 | ▶ | return ".${B}" if $oname =~ m,^$,; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | return $oname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 20 | ▶ | use File::Glob ':glob'; # standard use of module, which we need | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # as vanilla glob won't match whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 9 | ▶ | sub list_high_version { my( $template )=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_high_version: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 9 | ▶ | $template ||= ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$template ||= ""
MC/DC0%0/1
$template ||= ""
$template
Truth table50%1/2
A
A= $template
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 9 | my ($max, $n, $fname) = (-1, -1, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 9 | for (grep( /$template\d+$/, bsd_glob("$template*") )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 6 | ($n) = m/(\d+)$/; # extract number for comparisons | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 6 | ▶ | $max < $n and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | ($max, $fname) = ($n, $_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 9 | return ($max, $fname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # Tempting for program maintenance to combine computation of low and high, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # but that would make computation of the high (by far the most common call) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # pay a performance penalty for a seldom used value. So we separate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | ▶ | sub list_low_version { my( $template )=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_low_version: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | ▶ | $template ||= ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$template ||= ""
MC/DC0%0/1
$template ||= ""
$template
Truth table50%1/2
A
A= $template
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | my ($min, $n, $fname) = (-1, -1, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | for (grep( /$template\d+$/, bsd_glob("$template*") )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | ($n) = m/(\d+)$/; # extract number for comparisons | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | ▶ | $min > $n || $min < 0 and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$min > $n or $min < 0
MC/DC50%1/2
$min > $n or $min < 0
$min > $n
$min < 0
Truth table66%2/3
A or B
A= $min > $nB= $min < 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | ($min, $fname) = ($n, $_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | return ($min, $fname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | sub snag_opt_defaults { return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
snag_opt_defaults: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | as_dir => undef, # create node as dir (default is to | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # infer it from argument if possible) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | no_type_mismatch => 0, # complain if mismatch (default don't) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | mknextcopy => 0, # copy unnumbered file (default don't) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 10 | ▶ | sub snag_version { my( $template, $opt ) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
snag_version: called CC=23 SCAR=34.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 10 | ▶ | return (-1, "no base name given") if ! defined $template; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 10 | ▶ | $opt ||= snag_opt_defaults(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opt ||= snag_opt_defaults()
MC/DC0%0/2
$opt ||= snag_opt_defaults()
$opt
snag_opt_defaults()
Truth table33%1/3
A ||= B
A= $optB= snag_opt_defaults()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 10 | my $as_dir = $opt->{as_dir}; # might be undefined (ok) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Carve off terminal digit string $digits ("1" default). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 10 | ▶ | my $digits = ($template =~ s/(\d+)$//) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | ? $1 : "1"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 10 | my $vfmt = '%0'. length($digits) . 'd'; # version number format | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 10 | ▶ | $opt->{mknextcopy} and -f $template || # pre-condition of mknextcopy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$opt->{'mknextcopy'} && (-f $template || (return -1, "mknextcopy only works if '${template}' is a " . 'pre-existing file'))
-f $template or return -1, "mknextcopy only works if '${template}' is a " . 'pre-existing file'
MC/DC0%0/2
$opt->{'mknextcopy'} && (-f $template || (return -1, "mknextcopy only works if '${template}' is a " . 'pre-existing file'))
$opt->{'mknextcopy'}
-f $template
Truth table66%2/3
A && B
A= $opt->{'mknextcopy'}B= -f $template
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | return (-1, "mknextcopy only works if '$template' is a " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | . "pre-existing file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 8 | ▶ | $opt->{no_type_mismatch} ||= 0; # default this option to false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt->{"no_type_mismatch"} ||= 0
MC/DC0%0/1
$opt->{"no_type_mismatch"} ||= 0
$opt->{"no_type_mismatch"}
Truth table50%1/2
A
A= $opt->{"no_type_mismatch"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 8 | my ($hnum, $hnode) = list_high_version($template); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 8 | ▶ | if ($hnum == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 4 | ▶ | $as_dir ||= 0; # default type here is "file" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$as_dir ||= 0
MC/DC0%0/1
$as_dir ||= 0
$as_dir
Truth table50%1/2
A
A= $as_dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | $hnum = $digits - 1; # number we'll start trying for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | else { # current high is in $hnode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | my $isa_dir = -d $hnode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # Note that ||= can't be used to set default if 0 (or "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # is a valid specified value, as for $as_dir below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 4 | ▶ | if (defined $as_dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | $opt->{no_type_mismatch} and # if intolerant and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 4 | ▶ | ($isa_dir xor $as_dir) and # a mismatch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition57%4/7
$opt->{"no_type_mismatch"} and $isa_dir ^^ $as_dir
$isa_dir xor $as_dir
MC/DC33%1/3
$opt->{"no_type_mismatch"} and $isa_dir ^^ $as_dir
$opt->{"no_type_mismatch"}
$isa_dir
$as_dir
Truth table40%2/5
A and B xor C
A= $opt->{"no_type_mismatch"}B= $isa_dirC= $as_dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | return (-1, "high version ($hnode" . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | ($isa_dir ? "/" : "") . ") is a " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | ($isa_dir ? "directory" : "file") . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | ", different from type requested"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | $as_dir = $isa_dir; # infer type from $hnode | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 20 | ▶ | use constant MAX_TRIES => 3; # number of races we might run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 7 | my $hmax = $hnum + MAX_TRIES; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 7 | my ($try, $msg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 7 | ▶ | while (++$hnum <= $hmax) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 7 | $try = $template . sprintf($vfmt, $hnum); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 7 | ▶ | $msg = $as_dir ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | snag_dir($try) : snag_file($try); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 7 | ▶ | last if ! $msg; # success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | #return ($hnum, $try) if ! $msg; # success | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | return (-1, $msg) if $msg ne "1"; # error, not race | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 7 | ▶ | $msg and return (-1, "gave up after " . MAX_TRIES . " races lost"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # If we get here, $try contains the node that we snagged. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 7 | ▶ | if ($opt->{mknextcopy}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | ▶ | return (-1, "mknextcopy only works if '$try' is a file") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | unless -f $try; # re-check pre-condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 20 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | ▶ | copy($template, $try) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | return (-1, "mknextcopy failed: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 7 | return ($hnum, $try); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 2 | ▶ | sub snag_dir { my( $node )=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
snag_dir: called CC=4 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | ▶ | return "snag_dir: no directory given" if ! defined $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | ▶ | return "" if mkdir($node); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | return "1" if -e $node; # potential race condition detector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | return $!; # else return system error message | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 20 | ▶ | use Fcntl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 10 | ▶ | sub snag_file { my( $node )=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
snag_file: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 10 | ▶ | return "snag_file: no file given" if ! defined $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 10 | ▶ | return "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
sysopen FH, $node, 192 and close FH || 1
close FH or 1
MC/DC50%1/2
sysopen FH, $node, 192 and close FH || 1
sysopen FH, $node, 192
close FH
Truth table66%2/3
A and B
A= sysopen FH, $node, 192B= close FH
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # Create, but don't succeed if it doesn't exist (O_EXCL). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Return success even if for some reason the close fails. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | if sysopen(FH, $node, O_CREAT | O_EXCL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | && (close(FH) || 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | return "1" if -e $node; # potential race condition detector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | return $!; # else return system error message | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 20 | 1; # End of File::Value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||