DirectConnect/filelist.pm

filter: Statementstmt 18.4% 52 / 282 Branchbran 1.7% 3 / 170 Conditioncond 1.9% 3 / 158 MC/DCmcdc 1.1% 1 / 89 Subroutinesub 38.8% 14 / 36 Podpod 0.0% 0 / 2 totaltotal 9.9% 73 / 737 CC 154 SCAR 66.0
CC
154
Cov
10%
new
1640.0
__ANON__
1560.0
__ANON__
306.0
CRAP 731.7
« DirectConnect/pslib/pssql.pm ↑ Summary DirectConnect/adc.pm »
1 #$Id: filelist.pm 1001 2014-05-07 13:08:30Z pro $ $URL: svn://svn.setun.net/dcppp/trunk/lib/Net/DirectConnect/filelist.pm $
2  
3 =head1 SYNOPSIS
4  
5 generate dc++ xml filelist
6  
7 perl filelist.pm /path/to/dir
8  
9 =cut
10  
11 package # no cpan
12 Net::DirectConnect::filelist;
13 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use warnings "NONFATAL" => "all";
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶no if $] >= 5.017011, warnings => 'experimental::smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Data::Dumper; #dev only
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 $Data::Dumper::Sortkeys = $Data::Dumper::Useqq = $Data::Dumper::Indent = 1;
23 #use Net::DirectConnect;
24 1 ▶use Net::DirectConnect::adc;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 our $VERSION = ( split( ' ', '$Revision: 1001 $' ) )[1];
26  
27 =tofix
28 $0 =~ m|^(.+)[/\\].+?$|; #v0
29 our $root_path ||= $1 . '/' if $1;
30 $root_path =~ s|\\|/|g;
31 warn "rp[$root_path]";
32  
33 eval "use lib '$root_path./stat/pslib'";
34 eval "use lib '$root_path./../../../examples/stat/pslib';
35 use psmisc; use pssql;
36 use Net::DirectConnect;
37 use base 'Net::DirectConnect';
38 "; #use Net::DirectConnect;
39 #psmisc::use_try ('Net::DirectConnect');
40 =cut
41  
42 1 ▶use base 'Net::DirectConnect';
Subroutine BEGIN: called CC=1 SCAR=0.0
43 #use lib '../../../examples/stat/pslib'; # REMOVE
44 #use lib 'stat/pslib'; # REMOVE
45 1 ▶use lib::abs('pslib');
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use psmisc; # REMOVE
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use pssql; # REMOVE
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 our %config;
49 1 *config = *main::config;
50 1 ▶$config{ 'log_' . $_ } //= 0 for qw (dmp dcdmp dcdbg trace);
Condition100%2/2
$config{'log_' . $_} //= 0
l!l
13
MC/DC100%1/1
$config{'log_' . $_} //= 0
$config{'log_' . $_}
Truth table100%2/2
A
A= $config{'log_' . $_}
Aresult
11
00
51 1 ▶$config{ 'log_' . $_ } //= 1 for qw (screen default);
Condition50%1/2
$config{'log_' . $_} //= 1
l!l
02
MC/DC0%0/1
$config{'log_' . $_} //= 1
$config{'log_' . $_}
Truth table50%1/2
A
A= $config{'log_' . $_}
Aresult
11
00
52 1 ▶Net::DirectConnect::use_try 'Sys::Sendfile' unless $^O =~ /win/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $^O =~ /win/i 1 0 1
53 1 ▶Net::DirectConnect::use_try 'Sys::Sendfile::FreeBSD' if $^O =~ /freebsd/i;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /freebsd/i 0 1 1
54 #Net::DirectConnect::use_try 'IO::AIO';
55 1 my ( $tq, $rq, $vq );
56  
57 0 ▶sub skip ($$) {
Subroutine skip: not called CC=8 SCAR=42.8
Pod undocumented
58 0 my ( $file, $match ) = @_;
59 0 ▶ return unless length $match;
Branch: 1 branch
BranchTrueFalseTotal
unless length $match 0 0 0
60 #say join ' ', ('skptst', $file, $match,);
61 0 ▶ for my $m ( ref $match eq 'ARRAY' ? @$match : $match ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $match eq 'ARRAY' ? : 0 0 0
62 0 ▶ return 1 if ref $m eq 'Regexp' and $file =~ $m;
Branch: 1 branch
BranchTrueFalseTotal
if ref $m eq "Regexp" and $file =~ /$m/ 0 0 0
Condition0%0/3
ref $m eq "Regexp" and $file =~ /$m/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $m eq "Regexp" and $file =~ /$m/
ref $m eq "Regexp" $file =~ /$m/
Truth table0%0/3
A and B
A= ref $m eq "Regexp"B= $file =~ /$m/
ABresult
0X0
100
111
63 0 ▶ return 1 if !ref $m and $file eq $m;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $m and $file eq $m 0 0 0
Condition0%0/3
not ref $m and $file eq $m
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $m and $file eq $m
not ref $m $file eq $m
Truth table0%0/3
not(A) and B
A= not ref $mB= $file eq $m
ABresult
0X0
100
111
64 }
65 }
66  
67 0 ▶sub new {
Subroutine new: not called CC=40 SCAR=74.0
Pod undocumented
68 0 my $standalone = !ref $_[0];
69 0 ▶ my $self = ref $_[0] ? shift() : bless {}, $_[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
70 0 ▶ shift if $_[0] eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq __PACKAGE__ 0 0 0
71 #local %_ = @_;
72 #$self->{$_} = $_{$_} for keys %_;
73 0 $self->func(@_);
74 0 $self->init_main(@_);
75 0 ▶ $self->{'log'} //= sub (@) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
76 0 ▶ my $dc = ref $_[0] ? shift : $self || {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
Condition0%0/2
$self or {}
l!l
00
MC/DC0%0/1
$self or {}
$self
Truth table0%0/2
A
A= $self
Aresult
11
00
77 #print "PL[$_[0]]";
78 0 psmisc::printlog shift(), "[$dc->{'number'}]", @_,;
79 0 ▶ },;
Condition0%0/3
$self->{"log"} //= sub (@) { my $dc = ref $_[0] ? shift() : $self || {}; &psmisc::printlog(shift(), qq[[$dc->{"number"}]], @_); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"log"} //= sub (@) { my $dc = ref $_[0] ? shift() : $self || {}; &psmisc::printlog(shift(), qq[[$dc->{"number"}]], @_); }
$self->{"log"} sub (@) { my $dc = ref $_[0] ? shift() : $self || {}; &psmisc::printlog(shift(), qq[[$dc->{"number"}]], @_); }
Truth table0%0/3
A //= B
A= $self->{"log"}B= sub (@) { my $dc = ref $_[0] ? shift() : $self || {}; &psmisc::printlog(shift(), qq[[$dc->{"number"}]], @_); }
ABresult
1X1
011
000
80 0 ▶ $self->{no_sql} //= 0;
Condition0%0/2
$self->{"no_sql"} //= 0
l!l
00
MC/DC0%0/1
$self->{"no_sql"} //= 0
$self->{"no_sql"}
Truth table0%0/2
A
A= $self->{"no_sql"}
Aresult
11
00
81 #
82 # adjustable
83 #
84 0 ▶ $self->{files} //= 'files.xml';
Condition0%0/2
$self->{"files"} //= "files.xml"
l!l
00
MC/DC0%0/1
$self->{"files"} //= "files.xml"
$self->{"files"}
Truth table0%0/2
A
A= $self->{"files"}
Aresult
11
00
85 0 ▶ $self->{tth_cheat} //= 1_000_000; #try find file with same name-size-date
Condition0%0/2
$self->{"tth_cheat"} //= 1000000
l!l
00
MC/DC0%0/1
$self->{"tth_cheat"} //= 1000000
$self->{"tth_cheat"}
Truth table0%0/2
A
A= $self->{"tth_cheat"}
Aresult
11
00
86 0 ▶ $self->{tth_cheat_no_date} //= 0; #--//-- only name-size
Condition0%0/2
$self->{"tth_cheat_no_date"} //= 0
l!l
00
MC/DC0%0/1
$self->{"tth_cheat_no_date"} //= 0
$self->{"tth_cheat_no_date"}
Truth table0%0/2
A
A= $self->{"tth_cheat_no_date"}
Aresult
11
00
87 0 ▶ $self->{file_min} //= 0; #skip files smaller
Condition0%0/2
$self->{"file_min"} //= 0
l!l
00
MC/DC0%0/1
$self->{"file_min"} //= 0
$self->{"file_min"}
Truth table0%0/2
A
A= $self->{"file_min"}
Aresult
11
00
88 0 ▶ $self->{filelist_scan} //= 3600 * 1; #every seconds, 0 to disable
Condition0%0/2
$self->{"filelist_scan"} //= 3600
l!l
00
MC/DC0%0/1
$self->{"filelist_scan"} //= 3600
$self->{"filelist_scan"}
Truth table0%0/2
A
A= $self->{"filelist_scan"}
Aresult
11
00
89 0 ▶ $self->{filelist_reload} //= 300; #check and load filelist if new, every seconds
Condition0%0/2
$self->{"filelist_reload"} //= 300
l!l
00
MC/DC0%0/1
$self->{"filelist_reload"} //= 300
$self->{"filelist_reload"}
Truth table0%0/2
A
A= $self->{"filelist_reload"}
Aresult
11
00
90 0 ▶ $self->{filelist_fork} //= 1;
Condition0%0/2
$self->{"filelist_fork"} //= 1
l!l
00
MC/DC0%0/1
$self->{"filelist_fork"} //= 1
$self->{"filelist_fork"}
Truth table0%0/2
A
A= $self->{"filelist_fork"}
Aresult
11
00
91 0 ▶ $self->{file_send_by} //= 1024 * 1024 * 1;
Condition0%0/2
$self->{"file_send_by"} //= 1048576
l!l
00
MC/DC0%0/1
$self->{"file_send_by"} //= 1048576
$self->{"file_send_by"}
Truth table0%0/2
A
A= $self->{"file_send_by"}
Aresult
11
00
92 0 ▶ $self->{skip_hidden} //= 1;
Condition0%0/2
$self->{"skip_hidden"} //= 1
l!l
00
MC/DC0%0/1
$self->{"skip_hidden"} //= 1
$self->{"skip_hidden"}
Truth table0%0/2
A
A= $self->{"skip_hidden"}
Aresult
11
00
93 0 ▶ $self->{skip_symlink} //= 0;
Condition0%0/2
$self->{"skip_symlink"} //= 0
l!l
00
MC/DC0%0/1
$self->{"skip_symlink"} //= 0
$self->{"skip_symlink"}
Truth table0%0/2
A
A= $self->{"skip_symlink"}
Aresult
11
00
94 0 ▶ $self->{skip_dir} //= [ qr'(?:^|/)Incomplete(?:/|$)', ( !$self->{skip_hidden} ? () : qr{(?:^|/)\.} ), ];
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'skip_hidden'} ? : 0 0 0
Condition0%0/2
$self->{"skip_dir"} //= [qr"(?:^|/)Incomplete(?:/|$)", !$self->{"skip_hidden"} ? () : qr"(?:^|/)\."]
l!l
00
MC/DC0%0/1
$self->{"skip_dir"} //= [qr"(?:^|/)Incomplete(?:/|$)", !$self->{"skip_hidden"} ? () : qr"(?:^|/)\."]
$self->{"skip_dir"}
Truth table0%0/2
A
A= $self->{"skip_dir"}
Aresult
11
00
95 $self->{skip_file} //=
96 0 ▶ [ qr/\.(?:partial|(?:dc)tmp)$/i, qr/^~uTorrentPartFile_/i, ( !$self->{skip_hidden} ? () : qr{(?:^|/)\.} ), ];
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'skip_hidden'} ? : 0 0 0
Condition0%0/2
$self->{"skip_file"} //= [qr/\.(?:partial|(?:dc)tmp)$/i, qr/^~uTorrentPartFile_/i, !$self->{"skip_hidden"} ? () : qr"(?:^|/)\."]
l!l
00
MC/DC0%0/1
$self->{"skip_file"} //= [qr/\.(?:partial|(?:dc)tmp)$/i, qr/^~uTorrentPartFile_/i, !$self->{"skip_hidden"} ? () : qr"(?:^|/)\."]
$self->{"skip_file"}
Truth table0%0/2
A
A= $self->{"skip_file"}
Aresult
11
00
97 # $self->{sharesize_mul} //= 3; # make share bigger * sharefiles_mul
98 # $self->{sharesize_add} //= 10_000_000_000; #add to share size virtual bytes
99 # $self->{sharefiles_mul} //=3; #same for files for keeping size/files rate
100 # $self->{sharefiles_add} //= 10_000;
101 # $self->{no_auto_load_partial} //= 1;
102 #
103 # ==========
104 #
105 #$self->{share_full} //= {};
106 #$self->{share_tth} //= {};
107 ##$config{share_root} //= '';
108 0 ▶ $self->{'share'} = [ $self->{'share'} ] unless ref $self->{'share'};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"share"} 0 0 0
109 0 ▶ tr{\\}{/} for @{ $self->{'share'} || [] };
Condition0%0/2
$self->{'share'} || []
l!l
00
MC/DC0%0/1
$self->{'share'} || []
$self->{'share'}
Truth table0%0/2
A
A= $self->{'share'}
Aresult
11
00
110 0 Net::DirectConnect::adc::func($self);
111 0 $self->ID_get();
112 #$self->log('idr:', $self->{'INF'}{'ID'});
113 #$self->ID_get();
114 0 ▶ unless ( $self->{no_sql} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"no_sql"}) 0 0 0
115 local %_ = (
116 'driver' => 'sqlite',
117 #'dbname' => 'files',
118 'database' => 'files',
119 #'auto_connect' => 1,
120 #'log' => sub { shift if ref $_[0]; $self->log(@_) if $self },
121 'log' => $self->{'log'},
122 #'cp_in' => 'cp1251',
123 'connect_tries' => 0, 'connect_chain_tries' => 0, 'error_tries' => 0, 'error_chain_tries' => 0,
124 #insert_by => 1000,
125 #nav_all => 1,
126 #{}
127 #},
128 0 ▶ 'upgrade' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
129 0 ▶ my $db = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
130 $db->do("ALTER TABLE filelist ADD COLUMN $_")
131 0 for 'hit INTEGER UNSIGNED NOT NULL DEFAULT 0 ', 'sch INTEGER UNSIGNED NOT NULL DEFAULT 0 ';
132 #$db->do("UPDATE filelist SET hit=0, sch=0 WHERE hit IS NULL");
133 },
134 0 );
135 0 ▶ $self->{sql}{$_} //= $_{$_} for keys %_;
Condition0%0/3
$self->{"sql"}{$_} //= $_{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"sql"}{$_} //= $_{$_}
$self->{"sql"}{$_} $_{$_}
Truth table0%0/3
A //= B
A= $self->{"sql"}{$_}B= $_{$_}
ABresult
1X1
011
000
136 0 my ($short) = $self->{sql}{'driver'} =~ /mysql/;
137 0 ▶ my %table = (
Branch: 2 branches
BranchTrueFalseTotal
$short ? : 0 0 0
$short ? : 0 0 0
138 'filelist' => {
139 'path' => pssql::row(
140 undef,
141 'type' => 'VARCHAR',
142 'length' => ( $short ? 150 : 255 ),
143 'default' => '',
144 'index' => 1,
145 'primary' => 1
146 ),
147 'file' => pssql::row(
148 undef,
149 'type' => 'VARCHAR',
150 'length' => ( $short ? 150 : 255 ),
151 'default' => '',
152 'index' => 1,
153 'primary' => 1
154 ),
155 'tth' => pssql::row( undef, 'type' => 'VARCHAR', 'length' => 40, 'default' => '', 'index' => 1 ),
156 'size' => pssql::row( undef, 'type' => 'BIGINT', 'index' => 1, ),
157 'time' => pssql::row( 'time', ), #'index' => 1,
158 #'added' => pssql::row( 'added', ),
159 #'exists' => pssql::row( undef, 'type' => 'SMALLINT', 'index' => 1, ),
160 'hit' => pssql::row( undef, 'type' => 'INTEGER UNSIGNED NOT NULL DEFAULT 0 ', ),
161 'sch' => pssql::row( undef, 'type' => 'INTEGER UNSIGNED NOT NULL DEFAULT 0', ),
162 },
163 );
164 0 ▶ if ( $self->{db} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"db"}) 0 0 0
165 #warn 'preFL',Dumper $self->{db}{table}; #$config{'sql'};
166 0 $self->{db}{table}{$_} = $table{$_} for keys %table;
167 0 $self->{db}{upgrade} = $_{upgrade};
168 }
169 0 local %_ = ( 'table' => \%table, );
170 0 ▶ $self->{sql}{$_} //= $_{$_} for keys %_;
Condition0%0/3
$self->{"sql"}{$_} //= $_{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"sql"}{$_} //= $_{$_}
$self->{"sql"}{$_} $_{$_}
Truth table0%0/3
A //= B
A= $self->{"sql"}{$_}B= $_{$_}
ABresult
1X1
011
000
171 #warn ('sqlore:',Data::Dumper::Dumper $self->{'sql'}, \%_),
172 0 ▶ $self->{db} ||= pssql->new( %{ $self->{'sql'} || {} }, );
Condition0%0/5
$self->{"db"} ||= "pssql"->new(%{$self->{"sql"} or {};})
l!l&&r!l&&!r
000
$self->{'sql'} || {}
l!l
00
MC/DC0%0/2
$self->{"db"} ||= "pssql"->new(%{$self->{"sql"} or {};})
$self->{"db"} "pssql"->new(%{$self->{"sql"} or {};})
MC/DC0%0/1
$self->{'sql'} || {}
$self->{'sql'}
Truth table0%0/3
A ||= B
A= $self->{"db"}B= "pssql"->new(%{$self->{"sql"} or {};})
ABresult
1X1
011
000
Truth table0%0/2
A
A= $self->{'sql'}
Aresult
11
00
173 0 ( $tq, $rq, $vq ) = $self->{db}->quotes();
174 #$self->log('db', Dumper $self->{db});
175 #$self->log('db', 'flist', $self->{db});
176 }
177 0 ▶ $self->{filelist_make} //= sub {
Subroutine __ANON__: not called CC=16 SCAR=56.1
178 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
179 0 my $notth;
180 0 ▶ return unless psmisc::lock( 'sharescan', timeout => 0, old => 86400 );
Branch: 1 branch
BranchTrueFalseTotal
unless &psmisc::lock("sharescan", "timeout", 0, "old", 86400) 0 0 0
181 #$self->log( 'err', "sorry, cant load Net::DirectConnect::TigerHash for hashing" ), $notth = 1,
182 # unless Net::DirectConnect::use_try 'Net::DirectConnect::TigerHash'; #( $INC{"Net/DirectConnect/TigerHash.pm"} );
183 #$self->log( 'info',"ntth=[$notth]"); exit;
184 0 ▶ $self->log( 'err', 'forced db upgrade on make' ), $self->{db}->upgrade() if $self->{upgrade_force};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"upgrade_force"} 0 0 0
185 0 my $stopscan;
186 0 my $level = 0;
187 0 my $levelreal = 0;
188 0 my ( $sharesize, $sharefiles );
189 0 my $interrupted;
190 0 ▶ my $printinfo = sub () {
Subroutine __ANON__: not called CC=1 SCAR=6.9
191 0 $self->log( 'sharesize', psmisc::human( 'size', $sharesize ), $sharefiles, scalar keys %{ $self->{share_full} } );
192 0 };
193 0 ▶ local $SIG{INT} = sub { ++$stopscan; ++$interrupted; $self->log( 'warn', "INT rec, stopscan" ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
194 0 ▶ local $SIG{INFO} = sub { $printinfo->(); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
195 #$self->{'INF'}{'ID'}
196 psmisc::file_rewrite $self->{files}, qq{<?xml version="1.0" encoding="utf-8" standalone="yes"?>
197 0 ▶<FileListing Version="1" }, ( !$self->{'INF'}{'ID'} ? () : qq{CID="$self->{'INF'}{'ID'}" } ),
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'INF'}{'ID'} ? : 0 0 0
198 qq{Base="/" Generator="Net::DirectConnect $Net::DirectConnect::VERSION">
199 };
200 #<FileListing Version="1" CID="KIWZDBLTOFWIQOT6NWP7UOPJVDE2ABYPZJGN5TZ" Base="/" Generator="Net::DirectConnect $Net::DirectConnect::VERSION">
201 #};
202 0 my %o;
203 0 ▶ my $o = sub { our $n; $o{ $_[0] } = ++$n; @_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
204 0 our %table2filelist = (
205 $o->( file => 'Name' ),
206 $o->( size => 'Size' ),
207 $o->( tth => 'TTH' ),
208 $o->( time => 'TS' ),
209 $o->( hit => 'HIT' ),
210 $o->( sch => 'SCH' )
211 );
212 #warn Dumper \%o, \%table2filelist;
213 0 ▶ my $filelist_line = sub($) {
Subroutine __ANON__: not called CC=7 SCAR=40.3
214 0 for my $f (@_) {
215 0 ▶ next if !length $f->{file} or !length $f->{'tth'};
Branch: 1 branch
BranchTrueFalseTotal
unless length $f->{"file"} and length $f->{"tth"} 0 0 0
Condition0%0/3
length $f->{"file"} and length $f->{"tth"}
!ll&&!rl&&r
000
MC/DC0%0/2
length $f->{"file"} and length $f->{"tth"}
length $f->{"file"} length $f->{"tth"}
Truth table0%0/3
A and B
A= length $f->{"file"}B= length $f->{"tth"}
ABresult
0X0
100
111
216 #$f = {%$f};
217 0 $sharesize += $f->{size};
218 0 ▶ ++$sharefiles if $f->{size};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"size"} 0 0 0
219 #$f->{file} = Encode::encode( 'utf8', Encode::decode( $self->{charset_fs}, $f->{file} ) ) if $self->{charset_fs};
220 psmisc::file_append $self->{files}, "\t" x $level,
221 #qq{<File Name="$f->{file}" Size="$f->{size}" TTH="$f->{tth}" TS="$f->{time}"/>\n};
222 qq{<File}, (
223 0 map { qq{ $table2filelist{$_}="} . psmisc::html_chars( $a = $f->{$_} ) . qq{"} }
224 0 ▶ sort { $o{$a} <=> $o{$b} } grep { $table2filelist{$_} and $f->{$_} } keys %$f
Condition0%0/3
$Net::DirectConnect::filelist::table2filelist{$_} && $f->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::DirectConnect::filelist::table2filelist{$_} && $f->{$_}
$Net::DirectConnect::filelist::table2filelist{$_} $f->{$_}
Truth table0%0/3
A && B
A= $Net::DirectConnect::filelist::table2filelist{$_}B= $f->{$_}
ABresult
0X0
100
111
225 ),
226 qq{/>\n};
227 #$self->{share_full}{ $f->{tth} } = $f->{full} if $f->{tth}; $self->{share_full}{ $f->{file} } ||= $f->{full};
228 0 ▶ $f->{'full'} ||= $f->{'path'} . '/' . $f->{'file'};
Condition0%0/2
$f->{"full"} ||= $f->{"path"} . '/' . $f->{"file"}
l!l
00
MC/DC0%0/1
$f->{"full"} ||= $f->{"path"} . '/' . $f->{"file"}
$f->{"full"}
Truth table0%0/2
A
A= $f->{"full"}
Aresult
11
00
229  
230 =cu
231 $self->{share_full}{ $f->{'tth'} } = $f->{'full_local'}, $self->{share_tth}{ $f->{'full_local'} } = $f->{'tth'},
232 $self->{share_tth}{ $f->{'file'} } = $f->{'tth'},
233 if $f->{'tth'};
234 $self->{share_full}{ $f->{'file'} } ||= $f->{'full_local'};
235 =cut
236  
237 #$self->log 'set share', "[$f->{file}], [$f->{tth}] = [$self->{share_full}{ $f->{tth} }],[$self->{share_full}{ $f->{file} }]";
238 #$self->log Dumper $self->{share_full};
239 }
240 0 };
241 0 my $scandir;
242 0 ▶ $scandir = sub (@) {
Subroutine __ANON__: not called CC=39 SCAR=73.5
243 0 for my $dir (@_) {
244 #$self->log( 'scandir', $dir, 'charset', $self->{charset_fs} );
245 #$self->log( 'warn', 'stopscan', $stopscan),
246 0 ▶ last if $stopscan;
Branch: 1 branch
BranchTrueFalseTotal
if $stopscan 0 0 0
247 0 $dir =~ tr{\\}{/};
248 0 $dir =~ s{/+$}{};
249 0 ▶ opendir( my $dh, $dir ) or ( $self->log( 'err', "can't opendir [$dir]: $!\n" ), next );
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or $self->log("err", "can't opendir [$dir]: $!\n"), next 0 0 0
250 #$self->log( 'dev','sd', __LINE__,$dh);
251 #@dots =
252 0 ( my $dirname = $dir );
253 $dirname =
254 #Encode::encode 'utf8',
255 0 ▶ Encode::decode $self->{charset_fs}, $dirname, Encode::FB_WARN if $self->{charset_fs};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"charset_fs"} 0 0 0
256 #$self->log( 'dev','sd', __LINE__,$dh);
257 0 ▶ next if skip( $dirname, $self->{skip_dir} ) or ( $self->{skip_symlink} and -l $dirname );
Branch: 1 branch
BranchTrueFalseTotal
if &skip($dirname, $self->{"skip_dir"}) or $self->{"skip_symlink"} and -l $dirname 0 0 0
Condition0%0/6
&skip($dirname, $self->{"skip_dir"}) or $self->{"skip_symlink"} and -l $dirname
l!l&&r!l&&!r
000
$self->{"skip_symlink"} and -l $dirname
!ll&&!rl&&r
000
MC/DC0%0/3
&skip($dirname, $self->{"skip_dir"}) or $self->{"skip_symlink"} and -l $dirname
&skip($dirname, $self->{"skip_dir"}) $self->{"skip_symlink"} -l $dirname
Truth table0%0/4
A or B and C
A= &skip($dirname, $self->{"skip_dir"})B= $self->{"skip_symlink"}C= -l $dirname
ABCresult
1XX1
0111
00X0
0100
258 0 ▶ unless ($level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level) { } 0 0 0
259 0 for ( split '/', $dirname ) {
260 0 ▶ psmisc::file_append( $self->{files}, "\t" x $level, qq{<Directory Name="$_">\n} ), ++$level, if length $_;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ 0 0 0
261 }
262 } else {
263 0 $dirname =~
264 #W s/^\w://;
265 #$dirname =~
266 s{.*/}{};
267 0 ▶ psmisc::file_append( $self->{files}, "\t" x $level, qq{<Directory Name="$dirname">\n} ), ++$level, ++$levelreal,
Branch: 1 branch
BranchTrueFalseTotal
if length $dirname 0 0 0
268 if length $dirname;
269 }
270 #$self->log( 'dev','sd', __LINE__,$dh);
271 #Net::DirectConnect::
272 0 ▶ psmisc::schedule( [ 10, 10 ], our $my_every_10sec_sub__ ||= sub { $printinfo->() } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
our $my_every_10sec_sub__ ||= sub { &$printinfo(); }
l!l&&r!l&&!r
000
MC/DC0%0/2
our $my_every_10sec_sub__ ||= sub { &$printinfo(); }
our $my_every_10sec_sub__ sub { &$printinfo(); }
Truth table0%0/3
A ||= B
A= our $my_every_10sec_sub__B= sub { &$printinfo(); }
ABresult
1X1
011
000
273 #$self->log( 'readdir', );
274 0 FILE: for my $file ( readdir($dh) ) {
275 #$self->log( 'scanfile', $file, );
276 #$self->log( 'warn', 'stopscan', $stopscan),
277 0 ▶ last if $stopscan;
Branch: 1 branch
BranchTrueFalseTotal
if $stopscan 0 0 0
278 0 ▶ next if $file =~ /^\.\.?$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^\.\.?$/ 0 0 0
279 #$file = Encode::encode( 'utf8', Encode::decode( $self->{charset_fs}, $file ) ) if $self->{charset_fs};
280 0 my $f = { path => $dir, path_local => $dir, file => $file, file_local => $file, full_local => "$dir/$file", };
281 #$f->{full_local} = "$f->{path_local}/$f->{file_local}";
282 #print("d $f->{full}:\n"),
283 0 $f->{dir} = -d $f->{full_local};
284 #filelist_line($f),
285 0 ▶ if ( $f->{dir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"dir"}) 0 0 0
286 #next FILE if skip ($f->{file}, $self->{skip_dir});
287 0 $scandir->( $f->{full_local} );
288 0 next;
289 }
290 0 ▶ $f->{size} = -s $f->{full_local} if -f $f->{full_local};
Branch: 1 branch
BranchTrueFalseTotal
if -f $f->{"full_local"} 0 0 0
291 0 ▶ next if $f->{size} < $self->{file_min};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"size"} < $self->{"file_min"} 0 0 0
292 $f->{file} = #Encode::encode 'utf8',
293 0 ▶ Encode::decode $self->{charset_fs}, $f->{file}, Encode::FB_WARN if $self->{charset_fs};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"charset_fs"} 0 0 0
294 $f->{path} = #Encode::encode 'utf8',
295 0 ▶ Encode::decode $self->{charset_fs}, $f->{path}, Encode::FB_WARN if $self->{charset_fs};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"charset_fs"} 0 0 0
296 0 ▶ next FILE if skip( $f->{file}, $self->{skip_file} ) or ( $self->{skip_symlink} and -l $f->{file} );
Branch: 1 branch
BranchTrueFalseTotal
if &skip($f->{"file"}, $self->{"skip_file"}) or $self->{"skip_symlink"} and -l $f->{"file"} 0 0 0
Condition0%0/6
&skip($f->{"file"}, $self->{"skip_file"}) or $self->{"skip_symlink"} and -l $f->{"file"}
l!l&&r!l&&!r
000
$self->{"skip_symlink"} and -l $f->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/3
&skip($f->{"file"}, $self->{"skip_file"}) or $self->{"skip_symlink"} and -l $f->{"file"}
&skip($f->{"file"}, $self->{"skip_file"}) $self->{"skip_symlink"} -l $f->{"file"}
Truth table0%0/4
A or B and C
A= &skip($f->{"file"}, $self->{"skip_file"})B= $self->{"skip_symlink"}C= -l $f->{"file"}
ABCresult
1XX1
0111
00X0
0100
297 #$self->log( 'encfile', $f->{file} , "chs:$self->{charset_fs}");
298 0 $f->{full} = "$f->{path}/$f->{file}";
299 0 $f->{time} = int( $^T - 86400 * -M $f->{full_local} ); #time() -
300 #$self->log 'timed', $f->{time}, psmisc::human('date_time', $f->{time}), -M $f->{full_local}, int (86400 * -M $f->{full_local}), $^T;
301 #'res=',
302 #join "\n", grep { !/^\.\.?/ and
303 #/^\./ && -f "$dir/$_" }
304 #print " ", $file;
305 #todo - select not all cols
306 # $self->log('preselect', $self->{no_sql});
307 0 ▶ unless ( $self->{no_sql} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"no_sql"}) 0 0 0
308 #$self->log('select go',);# Dumper $f);
309 my $indb =
310 $self->{db}->line( "SELECT * FROM ${tq}filelist${tq} WHERE"
311 . " ${rq}path${rq}="
312 . $self->{db}->quote( $f->{path} )
313 . " AND ${rq}file${rq}="
314 . $self->{db}->quote( $f->{file} )
315 . " AND ${rq}size${rq}="
316 . $self->{db}->quote( $f->{size} )
317 . " AND ${rq}time${rq}="
318 . $self->{db}->quote( $f->{time} )
319 0 . " LIMIT 1" );
320 #$self->log('select', Dumper $indb);
321 #$self->log ('dev', 'already scaned', $indb->{size}),
322 0 ▶ $filelist_line->( { %$f, %$indb } ), next, if $indb->{size} ~~ $f->{size};
Branch: 1 branch
BranchTrueFalseTotal
if $indb->{"size"} ~~ $f->{"size"} 0 0 0
323 #$db->select('filelist', {path=>$f->{path},file=>$f->{file}, });
324 #$self->log Dumper ;
325 #print "\n";
326 #my $tth;
327 0 ▶ if ( $f->{size} > $self->{tth_cheat} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"size"} > $self->{"tth_cheat"}) 0 0 0
328 my $indb =
329 $self->{db}->line( "SELECT * FROM ${tq}filelist${tq} WHERE "
330 . "${rq}file${rq}="
331 . $self->{db}->quote( $f->{file} )
332 . " AND ${rq}size${rq}="
333 . $self->{db}->quote( $f->{size} )
334 0 ▶ . ( $self->{tth_cheat_no_date} ? () : " AND ${rq}time${rq}=" . $self->{db}->quote( $f->{time} ) )
Branch: 1 branch
BranchTrueFalseTotal
$self->{'tth_cheat_no_date'} ? : 0 0 0
335 . " LIMIT 1" );
336 #$self->log 'sel', Dumper $indb;
337 0 ▶ if ( $indb->{tth} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indb->{"tth"}) 0 0 0
338 0 $self->log( 'dev', "already summed", %$f, ' as ', %$indb );
339 0 ▶ $f->{$_} ||= $indb->{$_} for keys %$indb;
Condition0%0/3
$f->{$_} ||= $indb->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$f->{$_} ||= $indb->{$_}
$f->{$_} $indb->{$_}
Truth table0%0/3
A ||= B
A= $f->{$_}B= $indb->{$_}
ABresult
1X1
011
000
340 #filelist_line($f);
341 #next;
342 }
343 }
344 }
345 0 ▶ if ( !$notth and !$f->{tth} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($notth or $f->{"tth"}) 0 0 0
Condition0%0/3
$notth or $f->{"tth"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$notth or $f->{"tth"}
$notth $f->{"tth"}
Truth table0%0/3
A or B
A= $notthB= $f->{"tth"}
ABresult
1X1
011
000
346 #$self->log 'calc', $f->{full}, "notth=[$notth]";
347 0 my $time = time();
348 0 $f->{tth} = $self->hash_file( $f->{full_local} );
349 0 my $per = time - $time;
350 $self->log(
351 'time', $f->{full}, psmisc::human( 'size', $f->{size} ),
352 'per', psmisc::human( 'time_period', $per ),
353 0 ▶ 'speed ps', psmisc::human( 'size', $f->{size} / ( $per or 1 ) ),
Branch: 1 branch
BranchTrueFalseTotal
if $per > 1 0 0 0
Condition0%0/2
$per || 1
l!l
00
MC/DC0%0/1
$per || 1
$per
Truth table0%0/2
A
A= $per
Aresult
11
00
354 'total', psmisc::human( 'size', $sharesize )
355 )
356 if
357 #$f->{size} > 100_000 or
358 $per > 1;
359 }
360 #$f->{tth} = $f->{size} > 1_000_000 ? 'bigtth' : tthfile( $f->{full} ); #if -f $full;
361 #print Dumper $self->{share_full};
362 #next;
363 #print ' ', tthfile($full) if -f $full ; #and -s $full < 1_000_000;
364 #print ' ', $f->{tth};
365 #print ' ', $f->{size}; #if -f $f->{full};
366 #print join ':',-M $f->{full}, $^T + 86400 * -M $f->{full},$f->{time};
367 #print "\n";
368 0 $filelist_line->($f);
369 0 ▶ $self->{db}->insert_hash( 'filelist', $f ) if !$self->{no_sql} and $f->{tth};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"no_sql"} and $f->{"tth"} 0 0 0
Condition0%0/3
not $self->{"no_sql"} and $f->{"tth"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"no_sql"} and $f->{"tth"}
not $self->{"no_sql"} $f->{"tth"}
Truth table0%0/3
not(A) and B
A= not $self->{"no_sql"}B= $f->{"tth"}
ABresult
0X0
100
111
370 }
371 0 --$level;
372 0 --$levelreal;
373 0 psmisc::file_append $self->{files}, "\t" x $level, qq{</Directory>\n}; #<!-- $levelreal $level -->
374 0 closedir $dh;
375 }
376 0 ▶ if ( $levelreal < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($levelreal < 0) 0 0 0
377 #psmisc::file_append $self->{files}, "<!-- backing to root $levelreal $level -->\n";
378 0 ▶ psmisc::file_append $self->{files}, "\t" x $level, qq{</Directory>\n} while --$level >= 0;
Branch: 1 branch
BranchTrueFalseTotal
--$level >= 0 and do { &psmisc::file_append($self->{"files"}, scalar "\t" x $level, "</Directory>\n") } 0 0 0
379 0 $levelreal = $level = 0;
380 }
381 #$level
382 0 };
383 #else {
384 $self->log(
385 'info', "making filelist $self->{files} from",
386 0 ▶ @_, @{ $self->{'share'} || [] },
Condition0%0/2
$self->{'share'} || []
l!l
00
MC/DC0%0/1
$self->{'share'} || []
$self->{'share'}
Truth table0%0/2
A
A= $self->{'share'}
Aresult
11
00
387 'EXISTS=',
388 0 grep { -d } @_,
389 0 ▶ @{ $self->{'share'} || [] },
Condition0%0/2
$self->{'share'} || []
l!l
00
MC/DC0%0/1
$self->{'share'} || []
$self->{'share'}
Truth table0%0/2
A
A= $self->{'share'}
Aresult
11
00
390 );
391 #$self->{db}->do('ANALYZE filelist') unless $self->{no_sql};
392 0 ▶ $self->{db}->analyze('filelist') unless $self->{no_sql};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_sql"} 0 0 0
393 0 local %_;
394 0 ▶ $scandir->($_) for ( grep { !$_{$_}++ and -d } @_, @{ $self->{'share'} || [] }, );
Condition0%0/5
!$_{$_}++ && -d $_
!ll&&!rl&&r
000
$self->{'share'} || []
l!l
00
MC/DC0%0/2
!$_{$_}++ && -d $_
!$_{$_}++ -d $_
MC/DC0%0/1
$self->{'share'} || []
$self->{'share'}
Truth table0%0/3
not(A) && B
A= !$_{$_}++B= -d $_
ABresult
0X0
100
111
Truth table0%0/2
A
A= $self->{'share'}
Aresult
11
00
395 #undef $SIG{INT};
396 #undef $SIG{INFO};
397 0 psmisc::file_append $self->{files}, qq{</FileListing>};
398 0 psmisc::file_append $self->{files};
399 0 ▶ $self->{db}->flush_insert() unless $self->{no_sql};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_sql"} 0 0 0
400 0 local $_;
401 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
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) { } 0 0 0
Condition0%0/8
&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
!ll&&!rl&&r
000
$_ = !IO::Compress::Bzip2::bzip2($self->{"files"}, $self->{"files"} . '.bz2') or $self->log("bzip2 failed: ", $IO::Compress::Bzip2::Bzip2Error) and 0
l!l&&r!l&&!r
000
$self->log("bzip2 failed: ", $IO::Compress::Bzip2::Bzip2Error) and 0
!ll
00
MC/DC0%0/3
&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
&psmisc::use_try("IO::Compress::Bzip2") $_ = !IO::Compress::Bzip2::bzip2($self->{"files"}, $self->{"files"} . '.bz2') $self->log("bzip2 failed: ", $IO::Compress::Bzip2::Bzip2Error)
Truth table0%0/4
A and not(B) or C
A= &psmisc::use_try("IO::Compress::Bzip2")B= $_ = !IO::Compress::Bzip2::bzip2($self->{"files"}, $self->{"files"} . '.bz2')C= $self->log("bzip2 failed: ", $IO::Compress::Bzip2::Bzip2Error)
ABCresult
0XX0
1000
11X1
1011
402 psmisc::use_try 'IO::Compress::Bzip2'
403 and ($_ = !IO::Compress::Bzip2::bzip2( $self->{files} => $self->{files} . '.bz2' )
404 or $self->log( "bzip2 failed: ", $IO::Compress::Bzip2::Bzip2Error ) and 0 )
405 )
406 {
407 #$self->log('bzip',$self->{files} => $self->{files} . '.bz2');
408 0 () = $IO::Compress::Bzip2::Bzip2Error; #no warning
409 } else {
410 0 $self->log( 'dev', 'using system bzip2', $_, $!, ':', `bzip2 --force --keep "$self->{files}"` );
411 }
412 #unless $interrupted;
413 #$self->{share_full}{ $self->{files} . '.bz2' } = $self->{files} . '.bz2'; $self->{share_full}{ $self->{files} } = $self->{files};
414 #}
415 0 psmisc::unlock('sharescan');
416 0 $printinfo->();
417 #$SIG{INT} = $SIG{KILL} = undef;
418 0 return ( $sharesize, $sharefiles );
419 0 ▶ };
Condition0%0/3
$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"}, "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<FileListing Version=\"1\" ", !$self->{"INF"}{"ID"} ? () : qq[CID="$self->{"INF"}{"ID"}" ], qq[Base="/" Generator="Net::DirectConnect $Net::DirectConnect::VERSION">\n]); my %o; my $o = sub { our $n; $o{$_[0]} = ++$n; @_; } ; our(%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"}, scalar "\t" x $level, "<File", map({qq[ $table2filelist{$_}="] . &psmisc::html_chars($a = $f->{$_}) . '"';} (sort {$o{$a} <=> $o{$b};} grep({$table2filelist{$_} and $f->{$_};} keys %$f))), "/>\n"); $f->{"full"} ||= $f->{"path"} . '/' . $f->{"file"}; } ; } ; my $scandir; $scandir = sub (@) { foreach my $dir (@_) { last if $stopscan; $dir =~ tr[\\][/]; $dir =~ s[/+$][]; opendir my $dh, $dir or $self->log("err", "can't opendir [$dir]: $!\n"), next; my $dirname = $dir; $dirname = &Encode::decode($self->{"charset_fs"}, $dirname, 6) if $self->{"charset_fs"}; next if &skip($dirname, $self->{"skip_dir"}) or $self->{"skip_symlink"} and -l $dirname; if ($level) { $dirname =~ s[.*/][]; &psmisc::file_append($self->{"files"}, scalar "\t" x $level, qq[<Directory Name="$dirname">\n]), ++$level, ++$levelreal if length $dirname; } else { foreach $_ (split(m[/], $dirname, 0)) { &psmisc::file_append($self->{"files"}, scalar "\t" x $level, qq[<Directory Name="$_">\n]), ++$level if length $_; } ; } ; &psmisc::schedule([10, 10], scalar(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"}, 6) if $self->{"charset_fs"}; $f->{"path"} = &Encode::decode($self->{"charset_fs"}, $f->{"path"}, 6) if $self->{"charset_fs"}; next FILE if &skip($f->{"file"}, $self->{"skip_file"}) or $self->{"skip_symlink"} and -l $f->{"file"}; $f->{"full"} = qq[$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"}, scalar "\t" x $level, "</Directory>\n"); closedir $dh; } ; if ($levelreal < 0) { &psmisc::file_append($self->{"files"}, scalar "\t" x $level, "</Directory>\n") while --$level >= 0; $levelreal = $level = 0; } ; } ; $self->log("info", qq[making filelist $self->{"files"} from], @_, @{$self->{"share"} or [];}, "EXISTS=", grep({-d $_;} @_, @{$self->{"share"} or [];})); $self->{"db"}->analyze("filelist") unless $self->{"no_sql"}; local %_; &$scandir($_) foreach (grep {not $_{$_}++ and -d $_;} @_, @{$self->{"share"} or [];}); &psmisc::file_append($self->{"files"}, "</FileListing>"); &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; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$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"}, "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<FileListing Version=\"1\" ", !$self->{"INF"}{"ID"} ? () : qq[CID="$self->{"INF"}{"ID"}" ], qq[Base="/" Generator="Net::DirectConnect $Net::DirectConnect::VERSION">\n]); my %o; my $o = sub { our $n; $o{$_[0]} = ++$n; @_; } ; our(%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"}, scalar "\t" x $level, "<File", map({qq[ $table2filelist{$_}="] . &psmisc::html_chars($a = $f->{$_}) . '"';} (sort {$o{$a} <=> $o{$b};} grep({$table2filelist{$_} and $f->{$_};} keys %$f))), "/>\n"); $f->{"full"} ||= $f->{"path"} . '/' . $f->{"file"}; } ; } ; my $scandir; $scandir = sub (@) { foreach my $dir (@_) { last if $stopscan; $dir =~ tr[\\][/]; $dir =~ s[/+$][]; opendir my $dh, $dir or $self->log("err", "can't opendir [$dir]: $!\n"), next; my $dirname = $dir; $dirname = &Encode::decode($self->{"charset_fs"}, $dirname, 6) if $self->{"charset_fs"}; next if &skip($dirname, $self->{"skip_dir"}) or $self->{"skip_symlink"} and -l $dirname; if ($level) { $dirname =~ s[.*/][]; &psmisc::file_append($self->{"files"}, scalar "\t" x $level, qq[<Directory Name="$dirname">\n]), ++$level, ++$levelreal if length $dirname; } else { foreach $_ (split(m[/], $dirname, 0)) { &psmisc::file_append($self->{"files"}, scalar "\t" x $level, qq[<Directory Name="$_">\n]), ++$level if length $_; } ; } ; &psmisc::schedule([10, 10], scalar(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"}, 6) if $self->{"charset_fs"}; $f->{"path"} = &Encode::decode($self->{"charset_fs"}, $f->{"path"}, 6) if $self->{"charset_fs"}; next FILE if &skip($f->{"file"}, $self->{"skip_file"}) or $self->{"skip_symlink"} and -l $f->{"file"}; $f->{"full"} = qq[$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"}, scalar "\t" x $level, "</Directory>\n"); closedir $dh; } ; if ($levelreal < 0) { &psmisc::file_append($self->{"files"}, scalar "\t" x $level, "</Directory>\n") while --$level >= 0; $levelreal = $level = 0; } ; } ; $self->log("info", qq[making filelist $self->{"files"} from], @_, @{$self->{"share"} or [];}, "EXISTS=", grep({-d $_;} @_, @{$self->{"share"} or [];})); $self->{"db"}->analyze("filelist") unless $self->{"no_sql"}; local %_; &$scandir($_) foreach (grep {not $_{$_}++ and -d $_;} @_, @{$self->{"share"} or [];}); &psmisc::file_append($self->{"files"}, "</FileListing>"); &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; }
$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"}, "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<FileListing Version=\"1\" ", !$self->{"INF"}{"ID"} ? () : qq[CID="$self->{"INF"}{"ID"}" ], qq[Base="/" Generator="Net::DirectConnect $Net::DirectConnect::VERSION">\n]); my %o; my $o = sub { our $n; $o{$_[0]} = ++$n; @_; } ; our(%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"}, scalar "\t" x $level, "<File", map({qq[ $table2filelist{$_}="] . &psmisc::html_chars($a = $f->{$_}) . '"';} (sort {$o{$a} <=> $o{$b};} grep({$table2filelist{$_} and $f->{$_};} keys %$f))), "/>\n"); $f->{"full"} ||= $f->{"path"} . '/' . $f->{"file"}; } ; } ; my $scandir; $scandir = sub (@) { foreach my $dir (@_) { last if $stopscan; $dir =~ tr[\\][/]; $dir =~ s[/+$][]; opendir my $dh, $dir or $self->log("err", "can't opendir [$dir]: $!\n"), next; my $dirname = $dir; $dirname = &Encode::decode($self->{"charset_fs"}, $dirname, 6) if $self->{"charset_fs"}; next if &skip($dirname, $self->{"skip_dir"}) or $self->{"skip_symlink"} and -l $dirname; if ($level) { $dirname =~ s[.*/][]; &psmisc::file_append($self->{"files"}, scalar "\t" x $level, qq[<Directory Name="$dirname">\n]), ++$level, ++$levelreal if length $dirname; } else { foreach $_ (split(m[/], $dirname, 0)) { &psmisc::file_append($self->{"files"}, scalar "\t" x $level, qq[<Directory Name="$_">\n]), ++$level if length $_; } ; } ; &psmisc::schedule([10, 10], scalar(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"}, 6) if $self->{"charset_fs"}; $f->{"path"} = &Encode::decode($self->{"charset_fs"}, $f->{"path"}, 6) if $self->{"charset_fs"}; next FILE if &skip($f->{"file"}, $self->{"skip_file"}) or $self->{"skip_symlink"} and -l $f->{"file"}; $f->{"full"} = qq[$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"}, scalar "\t" x $level, "</Directory>\n"); closedir $dh; } ; if ($levelreal < 0) { &psmisc::file_append($self->{"files"}, scalar "\t" x $level, "</Directory>\n") while --$level >= 0; $levelreal = $level = 0; } ; } ; $self->log("info", qq[making filelist $self->{"files"} from], @_, @{$self->{"share"} or [];}, "EXISTS=", grep({-d $_;} @_, @{$self->{"share"} or [];})); $self->{"db"}->analyze("filelist") unless $self->{"no_sql"}; local %_; &$scandir($_) foreach (grep {not $_{$_}++ and -d $_;} @_, @{$self->{"share"} or [];}); &psmisc::file_append($self->{"files"}, "</FileListing>"); &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; }
Truth table0%0/3
A //= B
A= $self->{"filelist_make"}B= 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"}, "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<FileListing Version=\"1\" ", !$self->{"INF"}{"ID"} ? () : qq[CID="$self->{"INF"}{"ID"}" ], qq[Base="/" Generator="Net::DirectConnect $Net::DirectConnect::VERSION">\n]); my %o; my $o = sub { our $n; $o{$_[0]} = ++$n; @_; } ; our(%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"}, scalar "\t" x $level, "<File", map({qq[ $table2filelist{$_}="] . &psmisc::html_chars($a = $f->{$_}) . '"';} (sort {$o{$a} <=> $o{$b};} grep({$table2filelist{$_} and $f->{$_};} keys %$f))), "/>\n"); $f->{"full"} ||= $f->{"path"} . '/' . $f->{"file"}; } ; } ; my $scandir; $scandir = sub (@) { foreach my $dir (@_) { last if $stopscan; $dir =~ tr[\\][/]; $dir =~ s[/+$][]; opendir my $dh, $dir or $self->log("err", "can't opendir [$dir]: $!\n"), next; my $dirname = $dir; $dirname = &Encode::decode($self->{"charset_fs"}, $dirname, 6) if $self->{"charset_fs"}; next if &skip($dirname, $self->{"skip_dir"}) or $self->{"skip_symlink"} and -l $dirname; if ($level) { $dirname =~ s[.*/][]; &psmisc::file_append($self->{"files"}, scalar "\t" x $level, qq[<Directory Name="$dirname">\n]), ++$level, ++$levelreal if length $dirname; } else { foreach $_ (split(m[/], $dirname, 0)) { &psmisc::file_append($self->{"files"}, scalar "\t" x $level, qq[<Directory Name="$_">\n]), ++$level if length $_; } ; } ; &psmisc::schedule([10, 10], scalar(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"}, 6) if $self->{"charset_fs"}; $f->{"path"} = &Encode::decode($self->{"charset_fs"}, $f->{"path"}, 6) if $self->{"charset_fs"}; next FILE if &skip($f->{"file"}, $self->{"skip_file"}) or $self->{"skip_symlink"} and -l $f->{"file"}; $f->{"full"} = qq[$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"}, scalar "\t" x $level, "</Directory>\n"); closedir $dh; } ; if ($levelreal < 0) { &psmisc::file_append($self->{"files"}, scalar "\t" x $level, "</Directory>\n") while --$level >= 0; $levelreal = $level = 0; } ; } ; $self->log("info", qq[making filelist $self->{"files"} from], @_, @{$self->{"share"} or [];}, "EXISTS=", grep({-d $_;} @_, @{$self->{"share"} or [];})); $self->{"db"}->analyze("filelist") unless $self->{"no_sql"}; local %_; &$scandir($_) foreach (grep {not $_{$_}++ and -d $_;} @_, @{$self->{"share"} or [];}); &psmisc::file_append($self->{"files"}, "</FileListing>"); &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; }
ABresult
1X1
011
000
420 0 ▶ $self->{share_add_file} //= sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
421 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
422 0 my ( $full_local, $tth, $file ) = @_;
423 0 ▶ $full_local =~ m{([^/\\]+)$} unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
424 0 ▶ $file //= $1; # unless length $file;
Condition0%0/3
$file //= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$file //= $1
$file $1
Truth table0%0/3
A //= B
A= $fileB= $1
ABresult
1X1
011
000
425 #$full_local = Encode::encode $self->{charset_fs}, Encode::decode 'utf8', $full_local;
426 0 ▶ $self->{share_full}{$tth} = $full_local, $self->{share_tth}{$full_local} = $tth, $self->{share_tth}{$file} = $tth, if $tth;
Branch: 1 branch
BranchTrueFalseTotal
if $tth 0 0 0
427 0 ▶ $self->{share_full}{$file} ||= $full_local if $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file 0 0 0
Condition0%0/3
$self->{"share_full"}{$file} ||= $full_local
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"share_full"}{$file} ||= $full_local
$self->{"share_full"}{$file} $full_local
Truth table0%0/3
A ||= B
A= $self->{"share_full"}{$file}B= $full_local
ABresult
1X1
011
000
428 #$self->share_changed();
429 0 ▶ };
Condition0%0/3
$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; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$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; }
$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; }
Truth table0%0/3
A //= B
A= $self->{"share_add_file"}B= 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; }
ABresult
1X1
011
000
430 0 ▶ $self->{share_changed} //= sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
431 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
432 #$self->log('dev', "share_changed");
433 0 ▶ if ( $self->{'status'} eq 'connected' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"status"} eq "connected") 0 0 0
434 0 ▶ if ( $self->{adc} ) { $self->cmd( 'I', 'INF', undef, 'SS', 'SF' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'adc'}) { } 0 0 0
435 0 else { $self->cmd('MyINFO'); }
436 }
437 0 ▶ };
Condition0%0/3
$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"); } ; } ; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$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"); } ; } ; }
$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"); } ; } ; }
Truth table0%0/3
A //= B
A= $self->{"share_changed"}B= 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"); } ; } ; }
ABresult
1X1
011
000
438 0 ▶ $self->{filelist_load} //= sub { #{'cmd'}
Subroutine __ANON__: not called CC=17 SCAR=57.2
439 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
440 0 ▶ $self->log( 'err', 'forced db upgrade on load' ), $self->{db}->upgrade() if $self->{upgrade_force};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"upgrade_force"} 0 0 0
441  
442 =old
443 if ( $config{filelist} and open my $f, '<', $config{filelist} ) {
444 $self->log "loading filelist..";
445 local $/ = '<';
446 while (<$f>) {
447 if ( my ( $file, $time, $tiger ) = /^File Name="([^"]+)" TimeStamp="(\d+)" Root="([^"]+)"/i ) {
448 #$self->{'share_tth'}{ $params->{TR} }
449 $file =~ tr{\\}{/};
450 $self->{share_full}{$tiger} = $file;
451 $self->{share_tth}{$file} = $tiger;
452 }
453 #<File Name="c:\distr\neo\tmp" TimeStamp="1242907656" Root="3OPSFH2JD2UPBV4KIZAPLMP65DSTMNZRTJCYR4A"/>
454 }
455 close $f;
456 $self->log ".done:", ( scalar keys %{ $self->{share_full} } ), "\n";
457 }
458 =cut
459  
460 #$self->log( "filelist_load try", $global{shareloaded}, -s $self->{files}, ); #ref $_[0]
461 return
462 if !$self->{files}
463 or $Net::DirectConnect::global{shareloaded} == -s $self->{files}
464 or
465 ( $Net::DirectConnect::global{shareloaded} and !psmisc::lock( 'sharescan', readonly => 1, timeout => 0, old => 86400 ) )
466 0 ▶ or !open my $f, '<:encoding(utf8)', $self->{files};
Branch: 1 branch
BranchTrueFalseTotal
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"}) 0 0 0
Condition0%0/12
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"})
l!l&&r!l&&!r
000
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)
l!l&&r!l&&!r
000
not $self->{"files"} or $Net::DirectConnect::global{"shareloaded"} == -s $self->{"files"}
l!l&&r!l&&!r
000
$Net::DirectConnect::global{"shareloaded"} and not &psmisc::lock("sharescan", "readonly", 1, "timeout", 0, "old", 86400)
!ll&&!rl&&r
000
MC/DC0%0/5
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"})
not $self->{"files"} $Net::DirectConnect::global{"shareloaded"} == -s $self->{"files"} $Net::DirectConnect::global{"shareloaded"} not &psmisc::lock("sharescan", "readonly", 1, "timeout", 0, "old", 86400) not open(my $f, "<:encoding(utf8)", $self->{"files"})
Truth table0%0/7
not(A) or B or C and not(D) or not(E)
A= not $self->{"files"}B= $Net::DirectConnect::global{"shareloaded"} == -s $self->{"files"}C= $Net::DirectConnect::global{"shareloaded"}D= not &psmisc::lock("sharescan", "readonly", 1, "timeout", 0, "old", 86400)E= not open(my $f, "<:encoding(utf8)", $self->{"files"})
ABCDEresult
1XXXX1
01XXX1
0011X1
000X11
001011
000X00
001000
467 0 my ( $sharesize, $sharefiles );
468 #$self->log( 'info', "loading filelist", -s $f );
469 0 $Net::DirectConnect::global{shareloaded} = -s $f;
470 0 local $/ = '<';
471 0 %{ $self->{share_full} } = %{ $self->{share_tth} } = ();
472 0 my $dir;
473 0 ▶ while (<$f>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $f)) 0 0 0
474 #<Directory Name="distr">
475 #<File Name="3470_2.x.rar" Size="18824575" TTH="CL3SVS5UWWSAFGKCQZTMGDD355WUV2QVLNNADIA"/>
476 0 ▶ if ( my ( $file, $size, $tth, $ts ) = m{^File Name="([^"]+)" Size="(\d+)" TTH="([^"]+)"}i ) {
Branch: 3 branches
BranchTrueFalseTotal
if (() = /^File Name="([^"]+)" Size="(\d+)" TTH="([^"]+)"/i) { } 0 0 0
elsif (my($curdir) = /^Directory Name="([^"]+)">/i) { } 0 0 0
elsif (m[^/Directory>]i) { } 0 0 0
477 0 my $full_local = ( my $full = "$dir/$file" );
478 #$self->log 'loaded', $dir, $file , $full;
479 #$full_local = Encode::encode $self->{charset_fs}, $full if $self->{charset_fs};
480 $full_local = Encode::encode $self->{charset_fs},
481 #Encode::decode 'utf8',
482 0 $full_local, Encode::FB_WARN;
483 0 $self->share_add_file( $full_local, $tth, $file );
484 0 ++$sharefiles;
485 0 $sharesize += $size;
486 #$self->{'share_tth'}{ $params->{TR} }
487 #$file =~ tr{\\}{/};
488 } elsif ( my ($curdir) = m{^Directory Name="([^"]+)">}i ) { #"mcedit
489 0 ▶ $dir .= ( ( !length $dir and $^O ~~ [ 'MSWin32', 'cygwin' ] ) ? () : '/' ) . $curdir;
Branch: 1 branch
BranchTrueFalseTotal
!length($dir) && $^O ~~ ['MSWin32', 'cygwin'] ? : 0 0 0
Condition0%0/3
not length $dir and $^O ~~ ["MSWin32", "cygwin"]
!ll&&!rl&&r
000
MC/DC0%0/2
not length $dir and $^O ~~ ["MSWin32", "cygwin"]
not length $dir $^O ~~ ["MSWin32", "cygwin"]
Truth table0%0/3
not(A) and B
A= not length $dirB= $^O ~~ ["MSWin32", "cygwin"]
ABresult
0X0
100
111
490 #$self->log 'now in', $dir;
491 #$self->{files}
492 } elsif (m{^/Directory>}i) {
493 0 $dir =~ s{(?:^|/)[^/]+$}{};
494 #$self->log 'now ba', $dir;
495 }
496 }
497 0 $self->{share_full}{ $self->{files} . '.bz2' } = $self->{files} . '.bz2';
498 0 $self->{share_full}{ $self->{files} } = $self->{files};
499 # $self->{'INF'}{'SS'} = $self->{'sharesize'} = $sharesize;
500 # $self->{'INF'}{'SF'} = $sharefiles;
501 $self->log(
502 'info',
503 "loaded filelist size",
504 $Net::DirectConnect::global{shareloaded},
505 ' : files=', $sharefiles, 'bytes=',
506 psmisc::human( 'size', $sharesize ),
507 0 scalar keys %{ $self->{share_full} },
508 0 "bzsize=", -s $self->{files} . '.bz2',
509 );
510 0 psmisc::unlock('sharescan');
511 #$_[0]->( $sharesize, $sharefiles ) if ref $_[0] ~~ 'CODE';
512 #( $self->{share_size} , $self->{share_files} ) = ( $sharesize, $sharefiles );
513 0 ▶ $sharefiles *= $self->{sharefiles_mul} if $self->{sharefiles_mul};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"sharefiles_mul"} 0 0 0
514 0 $sharefiles += $self->{sharefiles_add};
515 0 ▶ $sharesize *= $self->{sharesize_mul} if $self->{sharesize_mul};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"sharesize_mul"} 0 0 0
516 0 $sharesize += $self->{sharesize_add};
517 0 ▶ $self->{sharefiles} = $self->{INF}{SF} = $sharefiles, $self->{INF}{SS} = $self->{sharesize} = $sharesize, if $sharesize;
Branch: 1 branch
BranchTrueFalseTotal
if $sharesize 0 0 0
518 0 $self->share_changed();
519 0 return ( $sharesize, $sharefiles );
520 0 ▶ };
Condition0%0/3
$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($_ = readline $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, 6); $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; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$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($_ = readline $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, 6); $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; }
$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($_ = readline $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, 6); $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; }
Truth table0%0/3
A //= B
A= $self->{"filelist_load"}B= 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($_ = readline $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, 6); $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; }
ABresult
1X1
011
000
521 0 ▶ $self->{search_stat_update} = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
522 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
523 0 ▶ my $tth = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tth = shift() or return 0 0 0
524 0 ▶ my $field = shift || 'hit';
Condition0%0/2
shift() || 'hit'
l!l
00
MC/DC0%0/1
shift() || 'hit'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
525 my $updated = $self->{db}->do(
526 "UPDATE ${tq}filelist${tq} SET ${rq}$field${rq}=${rq}$field${rq}+${vq}1${vq} WHERE "
527 #$self->{db}->do( "UPDATE ${tq}filelist${tq} SET ${rq}$field${rq}=${rq}$field${rq}+1 WHERE "
528 #$self->{db}->do( "UPDATE ${tq}filelist${tq} SET $field=$field+1 WHERE "
529 . "${rq}tth${rq}=" . $self->{db}->quote($tth)
530 #. ( $self->{db}{no_update_limit} ? () : " LIMIT ${vq}2${vq}" ) );
531 0 ▶ . ( $self->{db}{no_update_limit} ? () : " LIMIT 1" )
Branch: 1 branch
BranchTrueFalseTotal
$self->{'db'}{'no_update_limit'} ? : 0 0 0
532 );
533 0 ▶ $self->log( 'dev', "counter $field increased[$updated] on [$tth]" ) if $updated;
Branch: 1 branch
BranchTrueFalseTotal
if $updated 0 0 0
534 0 };
535 0 ▶ $self->{handler_int}{Search} //= sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
536 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
537 #$self->log ( 'dev', 'Search stat', Dumper @_) ;
538 #$self->log ( 'dev', 'Search stat', Dumper $_[1]{tth}) ;
539 0 $self->search_stat_update( $_[1]{tth}, 'sch' );
540 0 ▶ };
Condition0%0/3
$self->{"handler_int"}{"Search"} //= sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[1]{"tth"}, "sch"); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"handler_int"}{"Search"} //= sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[1]{"tth"}, "sch"); }
$self->{"handler_int"}{"Search"} sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[1]{"tth"}, "sch"); }
Truth table0%0/3
A //= B
A= $self->{"handler_int"}{"Search"}B= sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[1]{"tth"}, "sch"); }
ABresult
1X1
011
000
541 0 ▶ $self->{handler_int}{SCH} //= sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
542 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
543 #$self->log ( 'dev', 'SCH stat', Dumper @_) ;
544 0 $self->search_stat_update( $_[-1]{TR}, 'sch' );
545 0 ▶ };
Condition0%0/3
$self->{"handler_int"}{"SCH"} //= sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[-1]{"TR"}, "sch"); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"handler_int"}{"SCH"} //= sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[-1]{"TR"}, "sch"); }
$self->{"handler_int"}{"SCH"} sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[-1]{"TR"}, "sch"); }
Truth table0%0/3
A //= B
A= $self->{"handler_int"}{"SCH"}B= sub { my $self = shift() if ref $_[0]; $self->search_stat_update($_[-1]{"TR"}, "sch"); }
ABresult
1X1
011
000
546 0 ▶ $self->{'periodic'}{ __FILE__ . __LINE__ } = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
547 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
548 #$self->log ( 'periodic in filelist', $self->{filelist_scan}, caller );
549 psmisc::schedule(
550 #[10, $self->{filelist_scan}],
551 $self->{filelist_scan},
552 0 ▶ our $sharescan_sub__ ||= sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
553 0 my $self = shift;
554 $self->log(
555 'info',
556 'filelist actual age seconds:',
557 ( time - $^T + 86400 * -M $self->{files} ),
558 '<', $self->{filelist_scan}
559 0 );
560 return
561 if -e $self->{files}
562 and -s $self->{files} > 200
563 0 ▶ and $self->{filelist_scan} > time - $^T + 86400 * -M $self->{files};
Branch: 1 branch
BranchTrueFalseTotal
if -e $self->{"files"} and -s $self->{"files"} > 200 and $self->{"filelist_scan"} > time - $^T + 86400 * (-M $self->{"files"}) 0 0 0
Condition0%0/6
-e $self->{"files"} and -s $self->{"files"} > 200 and $self->{"filelist_scan"} > time - $^T + 86400 * (-M $self->{"files"})
!ll&&!rl&&r
000
-e $self->{"files"} and -s $self->{"files"} > 200
!ll&&!rl&&r
000
MC/DC0%0/3
-e $self->{"files"} and -s $self->{"files"} > 200 and $self->{"filelist_scan"} > time - $^T + 86400 * (-M $self->{"files"})
-e $self->{"files"} -s $self->{"files"} > 200 $self->{"filelist_scan"} > time - $^T + 86400 * (-M $self->{"files"})
Truth table0%0/4
A and B and C
A= -e $self->{"files"}B= -s $self->{"files"} > 200C= $self->{"filelist_scan"} > time - $^T + 86400 * (-M $self->{"files"})
ABCresult
0XX0
10X0
1100
1111
564 #$self->log( 'starter==','$0=',$0, $INC{'Net/DirectConnect/filelist.pm'}, $^X, 'share=', @{ $self->{'share'} } );
565 #$0 !~ m{(.*\W)?share.pl$}
566 !$self->{'filelist_fork'}
567 ? $self->filelist_make()
568 0 : $self->{'filelist_builder'} ? psmisc::start $self->{'filelist_builder'}, @{ $self->{'share'} } : psmisc::start $^X,
569 0 ▶ $INC{'Net/DirectConnect/filelist.pm'}, @{ $self->{'share'} };
Branch: 2 branches
BranchTrueFalseTotal
!$self->{'filelist_fork'} ? : 0 0 0
$self->{'filelist_builder'} ? : 0 0 0
570 #: psmisc::startme( 'filelist', grep { -d } @ARGV );
571 },
572 $self
573 0 ▶ ) if $self->{filelist_scan};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"filelist_scan"} 0 0 0
Condition0%0/3
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"};})); }
l!l&&r!l&&!r
000
MC/DC0%0/2
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"};})); }
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"};})); }
Truth table0%0/3
A ||= B
A= our $sharescan_sub__B= 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"};})); }
ABresult
1X1
011
000
574 #Net::DirectConnect::
575 psmisc::schedule(
576 #10, #dev! 300!
577 $self->{filelist_reload},
578 #our $filelist_load_sub__ ||=
579 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
580 0 my $self = shift;
581 #psmisc::startme( 'filelist', grep { -d } @ARGV );
582 #my($sharesize,$sharefiles) =
583 0 $self->filelist_load(
584 #sub {
585 #my ( $sharesize, $sharefiles ) = @_;
586 #$dc->{INF}{SS} = $sharesize, $dc->{INF}{SF} = $sharefiles, $dc->{sharesize} = $sharesize, if $sharesize;
587 ##todo! change INF cmd or myinfo
588 #}
589 );
590 },
591 $self
592 0 ▶ ) if $self->{filelist_scan};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"filelist_scan"} 0 0 0
593 },
594 #psmisc::startme( 'filelist', grep { -d } @ARGV ) if !-e $config{files} or !-e $config{files}.'.bz2';
595 0 ▶ $self->{handler_int}{file_recieved} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
596 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
597 0 my ( $full, $filename ) = @_;
598 #$self->{'file_recv_tth'} =
599 0 my ($tth) = $filename =~ m{^TTH/(\w+)};
600  
601 =z
602 return unless $tth;
603 $self->{share_full}{$tth} = $as;
604 my ($name) = $as =~ m{^([^/\\]+)$};
605 return unless $name;
606  
607 $self->{share_full}{$tth} = $full_local, $self->{share_tth}{$full_local} = $tth, $self->{share_tth}{$file} = $tth,
608 if $tth;
609 $self->{share_full}{$file} ||= $full_local;
610 =cut
611  
612 $self->log( 'dev', 'adding downloaded file to share', $full, $tth ),
613 $self->share_add_file( $full, $tth ), $self->share_changed()
614 0 ▶ if !$self->{'file_recv_filelist'} and !$self->{'no_auto_share_downloaded'}; # unless $self->{'no_auto_share_downloaded'};
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"file_recv_filelist"} || $self->{"no_auto_share_downloaded"} 0 0 0
Condition0%0/3
$self->{'file_recv_filelist'} || $self->{'no_auto_share_downloaded'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'file_recv_filelist'} || $self->{'no_auto_share_downloaded'}
$self->{'file_recv_filelist'} $self->{'no_auto_share_downloaded'}
Truth table0%0/3
A || B
A= $self->{'file_recv_filelist'}B= $self->{'no_auto_share_downloaded'}
ABresult
1X1
011
000
615 #TODO $self->{db}->insert_hash( 'filelist', $f ) if !$self->{no_sql} and $f->{tth};
616 ;
617 0 };
618 0 ▶ $self->filelist_load() unless $standalone; # (caller)[0] ~~ __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
unless $standalone 0 0 0
619 #$self->log('initok');
620 0 return $self;
621 }
622 1 ▶eval q{ #do
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
623 use lib '../..';
624 use Net::DirectConnect;
625 print "making\n";
626 __PACKAGE__->new(@ARGV)->{db}->upgrade(), exit if $ARGV[0] eq 'upgrade';
627 __PACKAGE__->new(@ARGV)->filelist_make(@ARGV),;
628 }, print $@ unless caller;
629 1 1;
« DirectConnect/pslib/pssql.pm ↑ Summary DirectConnect/adc.pm »