Condition Coverage

blib/lib/Net/DirectConnect/filelist.pm
Criterion Covered Total %
condition 0 128 0.0


and 3 conditions

line !l l&&!r l&&r condition
62 0 0 0 ref $m eq 'Regexp' and $file =~ /$m/
63 0 0 0 not ref $m and $file eq $m
215 0 0 0 length $$f{'file'} and length $$f{'tth'}
257 0 0 0 $$self{'skip_symlink'} and -l $dirname
296 0 0 0 $$self{'skip_symlink'} and -l $$f{'file'}
369 0 0 0 not $$self{'no_sql'} and $$f{'tth'}
401 0 0 0 &psmisc::use_try('IO::Compress::Bzip2') and ($_ = !IO::Compress::Bzip2::bzip2($$self{'files'}, $$self{'files'} . '.bz2')) || $self->log('bzip2 failed: ', $IO::Compress::Bzip2::Bzip2Error) && 0
462 0 0 0 $Net::DirectConnect::global{'shareloaded'} and not &psmisc::lock('sharescan', 'readonly', 1, 'timeout', 0, 'old', 86400)
489 0 0 0 !length($dir) && $^O ~~ ['MSWin32', 'cygwin']
561 0 0 0 -e $$self{'files'} and -s $$self{'files'} > 200
0 0 0 -e $$self{'files'} and -s $$self{'files'} > 200 and $$self{'filelist_scan'} > time - $^T + 86400 * (-M $$self{'files'})

or 2 conditions

line l !l condition
76 0 0 $self || {}
79 0 0 $$self{'log'} //= sub (@) { my $dc = ref $_[0] ? shift() : $self || {}; &psmisc::printlog(shift(), "[$$dc{'number'}]", @_); }
80 0 0 $$self{'no_sql'} //= 0
84 0 0 $$self{'files'} //= 'files.xml'
85 0 0 $$self{'tth_cheat'} //= 1000000
86 0 0 $$self{'tth_cheat_no_date'} //= 0
87 0 0 $$self{'file_min'} //= 0
88 0 0 $$self{'filelist_scan'} //= 3600
89 0 0 $$self{'filelist_reload'} //= 300
90 0 0 $$self{'filelist_fork'} //= 1
91 0 0 $$self{'file_send_by'} //= 1048576
92 0 0 $$self{'skip_hidden'} //= 1
93 0 0 $$self{'skip_symlink'} //= 0
94 0 0 $$self{'skip_dir'} //= [qr"(?:^|/)Incomplete(?:/|$)", !$$self{'skip_hidden'} ? () : qr"(?:^|/)\."]
95 0 0 $$self{'skip_file'} //= [qr/\.(?:partial|(?:dc)tmp)$/i, qr/^~uTorrentPartFile_/i, !$$self{'skip_hidden'} ? () : qr"(?:^|/)\."]
272 0 0 our $my_every_10sec_sub__ ||= sub { &$printinfo(); }
350 0 0 $per || 1
419 0 0 $$self{'filelist_make'} //= sub { my $self = shift() if ref $_[0]; my $notth; return unless &psmisc::lock('sharescan', 'timeout', 0, 'old', 86400); $self->log('err', 'forced db upgrade on make'), $$self{'db'}->upgrade if $$self{'upgrade_force'}; my $stopscan; my $level = 0; my $levelreal = 0; my($sharesize, $sharefiles); my $interrupted; my $printinfo = sub () { $self->log('sharesize', &psmisc::human('size', $sharesize), $sharefiles, scalar keys %{$$self{'share_full'};}); } ; local $SIG{'INT'} = sub { ++$stopscan; ++$interrupted; $self->log('warn', 'INT rec, stopscan'); } ; local $SIG{'INFO'} = sub { &$printinfo(); } ; &psmisc::file_rewrite($$self{'files'}, qq[\n\n]); my %o; my $o = sub { our $n; $o{$_[0]} = ++$n; @_; } ; our(%Net::DirectConnect::filelist::table2filelist) = (&$o('file', 'Name'), &$o('size', 'Size'), &$o('tth', 'TTH'), &$o('time', 'TS'), &$o('hit', 'HIT'), &$o('sch', 'SCH')); my $filelist_line = sub ($) { foreach my $f (@_) { next unless length $$f{'file'} and length $$f{'tth'}; $sharesize += $$f{'size'}; ++$sharefiles if $$f{'size'}; &psmisc::file_append($$self{'files'}, "\t" x $level, ' $o{$b};} grep({$$f{$_} if $table2filelist{$_};} keys %$f))), "/>\n"); $$f{'full'} ||= $$f{'path'} . '/' . $$f{'file'}; } ; } ; my $scandir; $scandir = sub (@) { foreach my $dir (@_) { last if $stopscan; $dir =~ tr[\\][/]; $dir =~ s[/+$][]; $self->log('err', "can't opendir [$dir]: $!\n"), next unless opendir my $dh, $dir; my $dirname = $dir; $dirname = &Encode::decode($$self{'charset_fs'}, $dirname, &Encode::FB_WARN()) if $$self{'charset_fs'}; next if skip $dirname, $$self{'skip_dir'} or $$self{'skip_symlink'} and -l $dirname; if (not $level) { foreach $_ (split(m[/], $dirname, 0)) { &psmisc::file_append($$self{'files'}, "\t" x $level, qq[\n]), ++$level if length $_; } ; } else { $dirname =~ s[.*/][]; &psmisc::file_append($$self{'files'}, "\t" x $level, qq[\n]), ++$level, ++$levelreal if length $dirname; } ; &psmisc::schedule([10, 10], our $my_every_10sec_sub__ ||= sub { &$printinfo(); } ); FILE: foreach my $file (readdir $dh) { last if $stopscan; next if $file =~ /^\.\.?$/; my $f = {'path', $dir, 'path_local', $dir, 'file', $file, 'file_local', $file, 'full_local', "$dir/$file"}; $$f{'dir'} = -d $$f{'full_local'}; if ($$f{'dir'}) { &$scandir($$f{'full_local'}); next; } ; $$f{'size'} = -s $$f{'full_local'} if -f $$f{'full_local'}; next if $$f{'size'} < $$self{'file_min'}; $$f{'file'} = &Encode::decode($$self{'charset_fs'}, $$f{'file'}, &Encode::FB_WARN()) if $$self{'charset_fs'}; $$f{'path'} = &Encode::decode($$self{'charset_fs'}, $$f{'path'}, &Encode::FB_WARN()) if $$self{'charset_fs'}; next FILE if skip $$f{'file'}, $$self{'skip_file'} or $$self{'skip_symlink'} and -l $$f{'file'}; $$f{'full'} = "$$f{'path'}/$$f{'file'}"; $$f{'time'} = int $^T - 86400 * (-M $$f{'full_local'}); unless ($$self{'no_sql'}) { my $indb = $$self{'db'}->line("SELECT * FROM ${tq}filelist$tq WHERE" . " ${rq}path$rq=" . $$self{'db'}->quote($$f{'path'}) . " AND ${rq}file$rq=" . $$self{'db'}->quote($$f{'file'}) . " AND ${rq}size$rq=" . $$self{'db'}->quote($$f{'size'}) . " AND ${rq}time$rq=" . $$self{'db'}->quote($$f{'time'}) . ' LIMIT 1'); &$filelist_line({%$f, %$indb}), next if $$indb{'size'} ~~ $$f{'size'}; if ($$f{'size'} > $$self{'tth_cheat'}) { my $indb = $$self{'db'}->line("SELECT * FROM ${tq}filelist$tq WHERE " . "${rq}file$rq=" . $$self{'db'}->quote($$f{'file'}) . " AND ${rq}size$rq=" . $$self{'db'}->quote($$f{'size'}) . ($$self{'tth_cheat_no_date'} ? () : " AND ${rq}time$rq=" . $$self{'db'}->quote($$f{'time'})) . ' LIMIT 1'); if ($$indb{'tth'}) { $self->log('dev', 'already summed', %$f, ' as ', %$indb); $$f{$_} ||= $$indb{$_} foreach (keys %$indb); } ; } ; } ; unless ($notth or $$f{'tth'}) { my $time = time; $$f{'tth'} = $self->hash_file($$f{'full_local'}); my $per = time - $time; $self->log('time', $$f{'full'}, &psmisc::human('size', $$f{'size'}), 'per', &psmisc::human('time_period', $per), 'speed ps', &psmisc::human('size', $$f{'size'} / ($per || 1)), 'total', &psmisc::human('size', $sharesize)) if $per > 1; } ; &$filelist_line($f); $$self{'db'}->insert_hash('filelist', $f) if not $$self{'no_sql'} and $$f{'tth'}; } ; --$level; --$levelreal; &psmisc::file_append($$self{'files'}, "\t" x $level, "\n"); closedir $dh; } ; if ($levelreal < 0) { &psmisc::file_append($$self{'files'}, "\t" x $level, "\n") while --$level >= 0; $levelreal = $level = 0; } ; } ; $self->log('info', "making filelist $$self{'files'} from", @_, @{[] unless $$self{'share'};}, 'EXISTS=', grep({-d $_;} @_, @{[] unless $$self{'share'};})); $$self{'db'}->analyze('filelist') unless $$self{'no_sql'}; local %_; &$scandir($_) foreach (grep {-d $_ if not $_{$_}++;} @_, @{[] unless $$self{'share'};}); &psmisc::file_append($$self{'files'}, ''); &psmisc::file_append($$self{'files'}); $$self{'db'}->flush_insert unless $$self{'no_sql'}; local $_; if (&psmisc::use_try('IO::Compress::Bzip2') and ($_ = !IO::Compress::Bzip2::bzip2($$self{'files'}, $$self{'files'} . '.bz2')) || $self->log('bzip2 failed: ', $IO::Compress::Bzip2::Bzip2Error) && 0) { () = $IO::Compress::Bzip2::Bzip2Error; } else { $self->log('dev', 'using system bzip2', $_, $!, ':', `bzip2 --force --keep "$$self{'files'}"`); } ; &psmisc::unlock('sharescan'); &$printinfo(); return $sharesize, $sharefiles; }
429 0 0 $$self{'share_add_file'} //= sub { my $self = shift() if ref $_[0]; my($full_local, $tth, $file) = @_; $full_local =~ m(([^/\\]+)$) unless $file; $file //= $1; $$self{'share_full'}{$tth} = $full_local, $$self{'share_tth'}{$full_local} = $tth, $$self{'share_tth'}{$file} = $tth if $tth; $$self{'share_full'}{$file} ||= $full_local if $file; }
437 0 0 $$self{'share_changed'} //= sub { my $self = shift() if ref $_[0]; if ($$self{'status'} eq 'connected') { if ($$self{'adc'}) { $self->cmd('I', 'INF', undef, 'SS', 'SF'); } else { $self->cmd('MyINFO'); } ; } ; }
520 0 0 $$self{'filelist_load'} //= sub { my $self = shift() if ref $_[0]; $self->log('err', 'forced db upgrade on load'), $$self{'db'}->upgrade if $$self{'upgrade_force'}; return if not $$self{'files'} or $Net::DirectConnect::global{'shareloaded'} == -s $$self{'files'} or $Net::DirectConnect::global{'shareloaded'} and not &psmisc::lock('sharescan', 'readonly', 1, 'timeout', 0, 'old', 86400) or not open(my $f, '<:encoding(utf8)', $$self{'files'}); my($sharesize, $sharefiles); $Net::DirectConnect::global{'shareloaded'} = -s $f; local $/ = '<'; (%{$$self{'share_full'};}) = ((%{$$self{'share_tth'};}) = ()); my $dir; while (defined($_ = <$f>)) { if (my($file, $size, $tth, $ts) = /^File Name="([^"]+)" Size="(\d+)" TTH="([^"]+)"/i) { my $full_local = my $full = "$dir/$file"; $full_local = &Encode::encode($$self{'charset_fs'}, $full_local, &Encode::FB_WARN()); $self->share_add_file($full_local, $tth, $file); ++$sharefiles; $sharesize += $size; } elsif (my($curdir) = /^Directory Name="([^"]+)">/i) { $dir .= (!length($dir) && $^O ~~ ['MSWin32', 'cygwin'] ? () : '/') . $curdir; } elsif (m[^/Directory>]i) { $dir =~ s[(?:^|/)[^/]+$][]; } ; } ; $$self{'share_full'}{$$self{'files'} . '.bz2'} = $$self{'files'} . '.bz2'; $$self{'share_full'}{$$self{'files'}} = $$self{'files'}; $self->log('info', 'loaded filelist size', $Net::DirectConnect::global{'shareloaded'}, ' : files=', $sharefiles, 'bytes=', &psmisc::human('size', $sharesize), scalar keys %{$$self{'share_full'};}, 'bzsize=', -s $$self{'files'} . '.bz2'); &psmisc::unlock('sharescan'); $sharefiles *= $$self{'sharefiles_mul'} if $$self{'sharefiles_mul'}; $sharefiles += $$self{'sharefiles_add'}; $sharesize *= $$self{'sharesize_mul'} if $$self{'sharesize_mul'}; $sharesize += $$self{'sharesize_add'}; $$self{'sharefiles'} = $$self{'INF'}{'SF'} = $sharefiles, $$self{'INF'}{'SS'} = $$self{'sharesize'} = $sharesize if $sharesize; $self->share_changed; return $sharesize, $sharefiles; }
524 0 0 shift() || 'hit'
540 0 0 $$self{'handler_int'}{'Search'} //= sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[1]{'tth'}, 'sch'); }
545 0 0 $$self{'handler_int'}{'SCH'} //= sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[-1]{'TR'}, 'sch'); }
572 0 0 our $sharescan_sub__ ||= sub { my $self = shift(); $self->log('info', 'filelist actual age seconds:', time - $^T + 86400 * (-M $$self{'files'}), '<', $$self{'filelist_scan'}); return if -e $$self{'files'} and -s $$self{'files'} > 200 and $$self{'filelist_scan'} > time - $^T + 86400 * (-M $$self{'files'}); !$$self{'filelist_fork'} ? $self->filelist_make : ($$self{'filelist_builder'} ? &psmisc::start($$self{'filelist_builder'}, @{$$self{'share'};}) : &psmisc::start($^X, $INC{'Net/DirectConnect/filelist.pm'}, @{$$self{'share'};})); }

or 3 conditions

line l !l&&r !l&&!r condition
135 0 0 0 $$self{'sql'}{$_} //= $_{$_}
170 0 0 0 $$self{'sql'}{$_} //= $_{$_}
172 0 0 0 $$self{'db'} ||= 'pssql'->new(%{{} unless $$self{'sql'};})
228 0 0 0 $$f{'full'} ||= $$f{'path'} . '/' . $$f{'file'}
257 0 0 0 skip $dirname, $$self{'skip_dir'} or $$self{'skip_symlink'} and -l $dirname
296 0 0 0 skip $$f{'file'}, $$self{'skip_file'} or $$self{'skip_symlink'} and -l $$f{'file'}
339 0 0 0 $$f{$_} ||= $$indb{$_}
345 0 0 0 $notth or $$f{'tth'}
401 0 0 0 ($_ = !IO::Compress::Bzip2::bzip2($$self{'files'}, $$self{'files'} . '.bz2')) || $self->log('bzip2 failed: ', $IO::Compress::Bzip2::Bzip2Error) && 0
424 0 0 0 $file //= $1
427 0 0 0 $$self{'share_full'}{$file} ||= $full_local
462 0 0 0 not $$self{'files'} or $Net::DirectConnect::global{'shareloaded'} == -s $$self{'files'}
0 0 0 not $$self{'files'} or $Net::DirectConnect::global{'shareloaded'} == -s $$self{'files'} or $Net::DirectConnect::global{'shareloaded'} and not &psmisc::lock('sharescan', 'readonly', 1, 'timeout', 0, 'old', 86400)
0 0 0 not $$self{'files'} or $Net::DirectConnect::global{'shareloaded'} == -s $$self{'files'} or $Net::DirectConnect::global{'shareloaded'} and not &psmisc::lock('sharescan', 'readonly', 1, 'timeout', 0, 'old', 86400) or not open(my $f, '<:encoding(utf8)', $$self{'files'})
612 0 0 0 $$self{'file_recv_filelist'} || $$self{'no_auto_share_downloaded'}