Branch Coverage

lib/Apache/Logmonster/Utility.pm
Criterion Covered Total %
branch 215 716 30.0


line true false branch
69 0 0 unless ($self->is_interactive)
74 0 0 unless $question =~ /\A \p{Any}* \z/msx
79 0 0 if defined $p{'test_ok'}
83 0 0 if $default and not $pass
86 0 0 if $pass
88 0 0 if ($p{'timeout'}) { }
95 0 0 if ($Apache::Logmonster::Utility::EVAL_ERROR)
96 0 0 $Apache::Logmonster::Utility::EVAL_ERROR eq "alarm\n" ? :
103 0 0 if ($pass)
106 0 0 unless ($response eq $response2)
116 0 0 if $response
117 0 0 if $default
127 191 0 if ($mess)
129 181 10 if $$self{'debug'} or $p{'debug'}
137 0 5 unless my $file = shift()
148 1 4 unless -e $file
153 0 4 if ($p{'destdir'} and -d $p{'destdir'})
159 4 0 if ($self->is_writable($file, %args) and $self->is_writable($archive, %args))
164 4 0 if (-e $archive)
166 0 4 if $p{'mode'}
172 0 0 if $p{'sudo'} and $< != 0
174 0 0 unless -e $archive
177 0 0 if $p{'mode'}
190 0 0 if ($sudo and $cp)
213 0 3 unless my $file = $p{'file'} || $p{'file_or_dir'} || $p{'dir'}
216 0 3 if ($p{'sudo'})
219 0 0 unless $self->syscmd("$sudo $chmod $mode $file", 'debug', 0)
224 0 3 unless CORE::chmod oct $mode, $file
244 0 3 unless $file
245 0 3 unless -e $file
250 0 3 if $sudo
258 0 3 if ($uid =~ /\A[0-9]+\z/) { }
264 1 2 unless defined $nuid
268 0 2 if ($gid =~ /\A[0-9\-]+\z/) { }
274 0 2 unless defined $ngid
278 0 2 unless CORE::chown $nuid, $ngid, $file
298 0 1 unless $dir
301 0 1 if $recurse
303 0 1 if $group
308 0 1 unless $self->syscmd($cmd, %args)
312 0 1 if $recurse
321 0 3 unless my $dir = shift()
328 0 3 unless chdir $dir
331 0 6 unless $_
337 4 2 if (-f $file) { }
2 0 elsif (-d $file) { }
338 0 4 unless unlink $file
342 0 2 unless rmtree($file)
355 0 2 unless my $dir = shift()
366 0 2 if -e $dir and not -d $dir
370 1 1 unless (-d $dir)
374 0 1 unless (-d $dir)
378 0 0 unless (-d $dir)
380 0 0 unless $self->mkdir_system('dir', $dir, 'sudo', 1, %args)
386 0 2 unless chdir $dir
394 0 13 unless my $audit = $$Apache::Logmonster::Utility::log{'audit'}
395 13 0 unless $$Apache::Logmonster::Utility::log{'last_audit'}
396 0 0 if $$Apache::Logmonster::Utility::log{'last_audit'} == scalar @$audit
398 0 0 if ($p{'quiet'})
414 2 8 unless my $last_line = $$Apache::Logmonster::Utility::log{'last_error'}
416 0 8 if $last_line == scalar @{$$Apache::Logmonster::Utility::log{'errors'};}
422 52 21 if $i < $last_line
436 0 1 unless mkpath($dir, 0, 493)
455 16 0 if ($message) { }
468 10 6 if ($debug or $fatal)
473 0 16 if $fatal
479 0 2 unless my $archive = shift()
485 1 1 unless (-e $archive)
486 0 1 if (-e "$archive.tar.gz") { }
0 1 elsif (-e "$archive.tgz") { }
0 1 elsif (-e "$archive.tar.bz2") { }
498 0 1 unless $archive =~ /[bz2|gz]$/
511 1 0 $archive =~ /gz$/ ? :
0 1 $archive =~ /bz2$/ ? :
517 0 1 unless grep /$types{$type}{'content'}/, `$file $archive`
522 0 1 unless $self->syscmd("$bin -c $archive | $tar -xf -")
530 0 6 unless my $file = shift()
539 1 5 unless -e $file
541 5 0 if (-w $file)
544 0 5 unless unlink $file
550 0 0 unless ($p{'sudo'})
551 0 0 -e $file ? :
558 0 0 if ($< != 0)
564 0 0 unless $self->syscmd($rm_command, %args)
567 0 0 -e $file ? :
591 1 1 if $stat2 > $stat1
604 0 7 unless my $file = shift()
616 0 7 unless -e $file
617 0 7 unless -r $file
619 0 7 unless open my $FILE, '<', $file
624 7 0 unless ($max_lines)
634 0 0 if ($max_length) { }
636 0 0 unless $line
637 0 0 if eof $FILE
657 0 1 unless -e $file
675 0 9 unless my $file = shift()
689 0 9 if -d $file
690 0 9 unless $self->is_writable($file, %args)
696 3 6 if ($append)
699 3 0 if (-f $file)
700 0 3 unless copy($file, "$file.tmp")
705 0 9 unless open my $HANDLE, $write_mode, "$file.tmp"
710 0 9 unless close $HANDLE
714 0 9 unless move("$file.tmp", $file)
718 0 9 if $p{'mode'}
738 0 5 unless (-e $f1 and -e $f2)
743 2 3 if $type ne 'text'
764 0 2 if $Apache::Logmonster::Utility::EVAL_ERROR
775 2 2 if (-f "$f.md5")
781 3 1 if (not -f "$f.md5" && $sum =~ /[0-9a-f]+/i or $self->file_is_newer('f1', "$f.md5", 'f2', $f, %$args))
795 3 1 if $changed
798 1 1 if $md5sums[0] eq $md5sums[1]
804 0 26 unless my $bin = shift()
814 0 26 if ($bin =~ m[^/] and -x $bin)
820 0 26 if $p{'dir'}
829 24 145 if (-x "$prefix/$bin")
830 24 0 if $found = "$prefix/$bin"
834 24 2 if ($found)
844 0 4 unless my $file = shift()
858 1 3 if $etcdir and -d $etcdir
863 2 2 if ($r)
869 0 2 if (-r "./$file-dist")
880 2 14 unless my $dir = shift()
883 2 12 if (-r "$dir/$file")
888 5 7 unless (-d $dir)
893 0 7 unless (-r $dir)
899 0 7 if (-e "$dir/$file")
910 0 1 if ($Apache::Logmonster::Utility::OSNAME eq 'darwin')
915 0 1 unless (-e $fstab)
916 0 0 if $p{'debug'}
983 0 4 unless my $dir = shift()
990 0 4 unless -d $dir
993 0 4 unless opendir D, $dir
996 8 139 if $f =~ /^\.\.?$/
1041 0 0 if $p{'exclude_ipv6'}
1042 0 0 if $p{'exclude_localhost'}
1043 0 0 if $p{'exclude_internals'}
1047 0 0 if (@ips < 1 or $ips[0] eq '')
1048 0 0 if $debug
1051 0 0 if $once < 2
1056 0 0 if $only eq 'first'
1057 0 0 if $only eq 'last'
1066 137 411 unless defined $p{$_}
1087 6 9 if $bump
1089 6 9 if $time != $offset_time
1093 15 0 unless ($Apache::Logmonster::Utility::EVAL_ERROR)
1134 0 1 unless -x $mount
1142 17 0 if ($m and $m =~ m[^/])
1143 17 0 if $p{'debug'}
1168 0 0 if $Apache::Logmonster::Utility::EVAL_ERROR
1174 0 0 if $dir
1179 0 0 if ($response)
1180 0 0 if ($response == 404) { }
0 0 elsif ($response == 304) { }
0 0 elsif ($response == 200) { }
1194 0 0 unless -e $file_path
1214 0 0 if ($Apache::Logmonster::Utility::OSNAME eq 'freebsd') { }
0 0 elsif ($Apache::Logmonster::Utility::OSNAME eq 'darwin') { }
1216 0 0 if ($fetchbin and -x $fetchbin)
1218 0 0 unless $debug
1223 0 0 if ($fetchbin and -x $fetchbin)
1225 0 0 unless $debug
1229 0 0 unless ($found)
1231 0 0 if $fetchbin and -x $fetchbin
1234 0 0 unless $found
1240 0 0 unless ($timeout)
1241 0 0 unless $self->syscmd($fetchcmd, %args)
1245 0 0 if (-e $file and $dir and -d $dir)
1260 0 0 if ($Apache::Logmonster::Utility::EVAL_ERROR)
1261 0 0 if $Apache::Logmonster::Utility::EVAL_ERROR eq "alarm\n"
1265 0 0 unless $r
1274 0 0 $ver ? :
1303 0 1 unless ($newfile =~ m[/])
1310 0 1 unless -e $newfile
1313 0 1 unless -f $newfile
1317 0 1 unless ($self->is_writable($existing, 'fatal', 0) and $self->is_writable($newfile, 'fatal', 0))
1321 0 0 if $Apache::Logmonster::Utility::UID == 0
1323 0 0 if ($sudo)
1324 0 0 unless $sudo = $self->find_bin('sudo', %args)
1330 1 0 if (-f $existing)
1335 1 0 unless ($diffie = $self->files_diff(%args, 'f1', $newfile, 'f2', $existing, 'type', 'text'))
1337 0 1 if $p{'clean'}
1344 0 0 if $uid and $gid
1353 0 0 if -e $existing and $mode
1362 0 0 if -e $existing and $p{'archive'}
1365 0 0 if $uid and $gid
1372 0 0 if $mode
1389 0 0 if ($sudo) { }
1393 0 0 if -e $existing
1397 0 0 if ($clean) { }
1408 0 0 if -e $existing
1410 0 0 if ($clean) { }
1411 0 0 unless move($newfile, $existing)
1415 0 0 unless copy($newfile, $existing)
1425 0 0 unless $notify
1426 0 0 unless -f $existing
1432 0 0 if $Apache::Logmonster::Utility::EVAL_ERROR
1463 2 0 if defined $p{'test_ok'}
1472 0 0 if $p{'source_sub_dir'}
1478 0 0 if ($bintest and $self->find_bin($bintest, 'fatal', 0, 'debug', 0))
1479 0 0 unless $self->yes_or_no("$bintest exists, suggesting that " . "$package is installed. Do you want to reinstall?", 'timeout', 60)
1488 0 0 unless $self->install_from_source_cleanup($package, $src)
1489 0 0 unless $self->install_from_source_get_files($package, $site, $url, $p{'patch_url'}, $patches)
1491 0 0 unless $self->extract_archive($package)
1496 0 0 if (-d $package) { }
1497 0 0 unless chdir $package
1507 0 0 if $sub_path
1508 0 0 unless -d $sub_path and chdir $sub_path
1512 0 0 unless $self->install_from_source_apply_patches($src, $patches, $patch_args)
1515 0 0 unless (@$targets[0])
1522 0 0 if $p{'debug'}
1527 0 0 if ($target =~ /^cd (.*)$/)
1529 0 0 unless chdir $1
1533 0 0 unless $self->syscmd($target, %args)
1539 0 0 if -d $package
1541 0 0 if defined $sub_path and -d "$package/$sub_path"
1552 0 0 unless $patches
1553 0 0 unless $$patches[0]
1557 0 0 unless $self->syscmd("$patchbin $patch_args < $src/$patch")
1568 0 0 unless -d $package
1570 0 0 unless $self->source_warning('package', $package, 'clean', 1, 'src', $src)
1584 0 0 unless $self->sources_get('package', $package, 'site', $site, 'path', $url)
1590 0 0 unless ($patches and $$patches[0])
1595 0 0 unless $patch_url
1600 0 0 unless $patch
1601 0 0 if -e $patch
1605 0 0 unless $self->get_url($url)
1615 0 0 if (lc $Apache::Logmonster::Utility::OSNAME eq 'freebsd')
1617 0 0 unless my $portname = $$info{'port'}
1620 0 0 if (`/usr/sbin/pkg_info | /usr/bin/grep $app`)
1628 0 0 unless -d $portdir and chdir $portdir
1631 0 0 if system 'make install clean'
1636 0 0 if (lc $Apache::Logmonster::Utility::OSNAME eq 'linux')
1637 0 0 unless my $rpm = $$info{'rpm'}
1639 0 0 unless -x $yum
1650 0 0 defined $info{'debug'} ? :
1655 0 0 unless ($Apache::Logmonster::Utility::EVAL_ERROR)
1659 0 0 if (lc $Apache::Logmonster::Utility::OSNAME eq 'darwin') { }
0 0 elsif (lc $Apache::Logmonster::Utility::OSNAME eq 'freebsd') { }
0 0 elsif (lc $Apache::Logmonster::Utility::OSNAME eq 'linux') { }
1660 0 0 if $self->install_module_darwin($module)
1663 0 0 if $self->install_module_freebsd($module, \%info)
1666 0 0 if $self->install_module_linux($module, \%info)
1674 0 0 unless ($Apache::Logmonster::Utility::EVAL_ERROR)
1694 0 0 if ($module eq 'Provision::Unix' and $version)
1706 0 0 unless -x $dport
1711 0 0 unless system "sudo $dport install $port"
1720 0 0 unless ($portname)
1726 0 0 if $r
1730 0 0 if ($portdir and -d $portdir and chdir $portdir)
1758 0 0 if (-d $module)
1759 0 0 unless ($self->source_warning('package', $module, 'src', $src, %args))
1767 0 0 unless $self->sources_get('site', $site, 'path', $url, 'package', $p{'archive'} || $module, %args)
1773 0 0 unless $self->extract_archive($module)
1779 0 0 unless -d $file
1780 0 0 unless $file =~ /$module/
1786 0 0 unless (@$targets[0] and @$targets[0] ne '')
1793 0 0 unless $self->syscmd('cmd', $_, %args)
1809 0 0 if ($rpm)
1813 0 0 if -x $yum
1825 0 0 unless -t $out_handle
1828 0 0 if (openhandle(*ARGV))
1831 0 0 if defined $ARGV and $ARGV eq '-'
1834 0 0 if eof ARGV
1851 0 2 if (lc($Apache::Logmonster::Utility::OSNAME) =~ /solaris/i) { }
0 2 elsif (lc($Apache::Logmonster::Utility::OSNAME) =~ /irix/i) { }
2 0 elsif (lc($Apache::Logmonster::Utility::OSNAME) =~ /linux/i) { }
1863 0 2 unless my $file = shift()
1868 1 1 unless -e $file
1869 0 1 unless -r $file
1878 0 22 unless my $file = shift()
1884 0 22 if $ENV{'GATEWAY_INTERFACE'}
1886 8 14 unless (-e $file)
1890 0 8 if -e $path and not -w $path
1896 0 14 unless -w $file
1918 0 3 unless open my $LOG_FILE, '>>', $file
1952 0 1 if -d $dir
1954 0 1 unless my $mkdir = $self->find_bin('mkdir', %args)
1957 1 0 if ($< == 0)
1958 0 1 unless $self->syscmd("$mkdir -p $dir", %args)
1959 0 1 if $mode
1961 1 0 if -d $dir
1965 0 0 if ($p{'sudo'})
1975 0 0 if $mode
1977 0 0 -d $dir ? :
1983 0 0 unless $self->syscmd("$mkdir -p $dir", %args)
1985 0 0 if $mode
1987 0 0 if -d $dir
1997 0 1 if ($dir =~ m[/$])
2018 0 3 unless $file
2019 1 2 if -e $file and not -f $file
2024 0 2 unless ($self->is_writable($file, %args))
2031 1 1 unless (-e $file)
2033 1 0 if $self->file_write($file, 'lines', [$Apache::Logmonster::Utility::PROCESS_ID], %args)
2038 1 0 if ($age < 1200) { }
0 0 elsif ($age < 3600) { }
2057 0 3 unless my $file = shift()
2066 1 2 unless (-f $file)
2068 1 2 unless ($file and -r $file)
2077 64 236 unless $_
2079 202 34 if $_ =~ /^#/
2080 0 34 if $_ =~ /^[\s+]?$/
2084 0 34 unless $key
2116 0 38 if ($strip and $val and $val =~ /#/)
2145 0 1 if ($pbp)
2146 0 0 if ($string =~ /($exp)/msx) { }
2147 0 0 if $debug
2151 0 0 if $debug
2156 1 0 if ($string =~ /($exp)/)
2157 0 1 if $debug
2161 0 0 if $debug
2183 0 0 unless my $filet = $self->find_bin('file', %args)
2184 0 0 unless my $grep = $self->find_bin('grep', %args)
2189 0 0 unless -e $tarball
2190 0 0 if -e $tarball
2192 0 0 if (`$filet $tarball | $grep compress`)
2193 0 0 if $self->yes_or_no("$tarball exists, shall I use it?: ")
2205 0 0 unless $self->get_url("$site$path/$tarball", 'fatal', 0)
2208 0 0 unless -e $tarball
2212 0 0 if (`$filet $tarball | $grep zip`)
2243 1 0 unless -d $package
2245 0 0 if (-e $package)
2250 0 0 unless $p{'clean'}
2253 0 0 unless ($self->yes_or_no("\n\tMay I remove the sources for you?", 'timeout', $p{'timeout'}))
2261 0 0 unless rmtree("$src/$package")
2271 1 0 if ($Apache::Logmonster::Utility::REAL_USER_ID == 0)
2280 0 0 if ($path_to_sudo and -x $path_to_sudo)
2288 0 0 unless ($self->yes_or_no('may I try to install sudo?', 'timeout', 20))
2293 0 0 unless -x $self->find_bin('sudo', 'fatal', 0)
2306 0 0 unless (-x $path_to_sudo)
2316 0 10 unless my $cmd = shift()
2331 10 0 if ($cmd =~ /\s+/mx) { }
2340 0 0 unless ($cmd =~ m[\./])
2343 0 10 if ($is_safe and not $bin)
2348 10 0 if $bin
2349 10 0 if $is_safe
2352 5 5 if ($bin and not -e $bin)
2353 0 5 unless $bin = $self->find_bin($bin, 'fatal', 0, 'debug', 0)
2359 0 10 if &Scalar::Util::tainted($cmd)
2366 0 10 if $tainted and not $is_safe
2369 10 0 if ($is_safe)
2371 0 10 if -d '/opt/local'
2377 1 9 if (defined $p{'timeout'})
2383 1 9 if defined $p{'timeout'}
2386 0 10 if ($Apache::Logmonster::Utility::EVAL_ERROR)
2387 0 0 if ($Apache::Logmonster::Utility::EVAL_ERROR eq "alarm\n") { }
2407 8 2 if $exit_code == 0
2412 0 2 if ($err == -1) { }
0 2 elsif ($err & 127) { }
2416 0 0 $? & 128 ? :
2436 1 0 if $question eq 'test'
2439 0 0 unless ($p{'force'} or $self->is_interactive)
2446 0 0 if $p{'timeout'}
2463 0 0 if ($p{'timeout'})
2475 0 0 if ($@)
2476 0 0 $@ eq "alarm\n" ? :
2479 0 0 $response && $response eq 'y' ? :
2488 0 0 $response eq 'y' ? :