| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::RRP::Toolkit; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
779
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
4
|
1
|
|
|
1
|
|
942
|
use Errno; |
|
|
1
|
|
|
|
|
4759
|
|
|
|
1
|
|
|
|
|
52
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use Fcntl ':flock'; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
1742
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@Net::RRP::Toolkit::ISA = qw(Exporter); |
|
9
|
|
|
|
|
|
|
@Net::RRP::Toolkit::EXPORT_OK = qw(decodeTilde safeCall safeCopy lowerKeys pathSubtract); |
|
10
|
|
|
|
|
|
|
$Net::RRP::Toolkit::VERSION = (split " ", '# $Id: Toolkit.pm,v 1.3 2000/10/04 08:05:37 mkul Exp $ ')[3]; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub decodeTilde |
|
13
|
|
|
|
|
|
|
{ |
|
14
|
0
|
|
0
|
0
|
1
|
|
my $path = shift || return undef; |
|
15
|
0
|
0
|
|
|
|
|
$path =~ s/^~([^\/]*)/$1 ? (getpwnam($1))[7] : (getpwuid($>))[7]/e; |
|
|
0
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
$path; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub safeCall |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
0
|
|
|
0
|
1
|
|
my $codeRef = shift; |
|
22
|
0
|
|
|
|
|
|
my $result = &$codeRef; |
|
23
|
0
|
|
0
|
|
|
|
while ( ( $! == Errno::EINTR ) && ( ! $result ) ) |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
0
|
|
|
|
|
|
$result = &$codeRef; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
0
|
|
|
|
|
|
$result; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub safeWrite |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
0
|
|
|
0
|
0
|
|
my ( $handler, $buffer, $length ) = @_; |
|
33
|
0
|
0
|
|
|
|
|
$handler || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'hander' }; |
|
34
|
0
|
0
|
|
|
|
|
defined $buffer || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'buffer' }; |
|
35
|
0
|
|
0
|
|
|
|
$length ||= length ( $buffer ); |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my ( $origLength, $itemLength ) = ( $length ); |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
while ( $length ) |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
0
|
|
|
0
|
|
|
$itemLength = Net::RRP::Toolkit::safeCall ( sub { $handler->syswrite ( $buffer, $length ) } ); |
|
|
0
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
last unless $itemLength; |
|
43
|
0
|
|
|
|
|
|
$length -= $itemLength; |
|
44
|
0
|
0
|
|
|
|
|
$buffer = substr ( $buffer, $itemLength ) if $length; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
defined $itemLength ? $origLength : undef; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub safeRead |
|
51
|
|
|
|
|
|
|
{ |
|
52
|
0
|
|
|
0
|
0
|
|
my ( $handler, $buffer, $length ) = @_; |
|
53
|
0
|
0
|
|
|
|
|
$handler || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'hander' }; |
|
54
|
0
|
0
|
|
|
|
|
defined $buffer || raise ZError 'MISSING_MANDATORY_PARAM', { name => 'buffer' }; |
|
55
|
0
|
|
0
|
|
|
|
$length ||= length ( $buffer ); |
|
56
|
0
|
|
|
|
|
|
$$buffer = ''; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my ( $origLength, $itemLength ) = ( $length ); |
|
59
|
0
|
|
|
|
|
|
my $subBuffer; |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
while ( $length ) |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
0
|
|
|
0
|
|
|
$itemLength = Net::RRP::Toolkit::safeCall ( sub { $handler->sysread ( $subBuffer, $length ) } ); |
|
|
0
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
last unless $itemLength; |
|
65
|
0
|
|
|
|
|
|
$length -= $itemLength; |
|
66
|
0
|
|
|
|
|
|
$$buffer .= $subBuffer; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
defined $itemLength ? $origLength : undef; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub safeCopy |
|
73
|
|
|
|
|
|
|
{ |
|
74
|
0
|
|
0
|
0
|
1
|
|
my $fromName = $_{srcFile} || die "safeCopy(): srcFile required"; |
|
75
|
0
|
|
0
|
|
|
|
my $toName = $_{dstFile} || die "safeCopy(): dstFile required"; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
0
|
|
|
|
my $bufferSize = $_{bufferSize} || 128; |
|
78
|
0
|
|
0
|
|
|
|
my $tmpMask = $_{tmpMask} || "$toName.$$.\%s"; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
local ( *FROMFILE, *TOFILE ) = ( undef, undef ); |
|
81
|
0
|
|
|
|
|
|
my ( $fromFileNum, $toFileNum, $tmpToName ) = ( 0, 0, '' ); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
eval |
|
84
|
0
|
|
|
|
|
|
{ |
|
85
|
|
|
|
|
|
|
die "sysopen ( $fromName, \"r\" ): $!" |
|
86
|
0
|
0
|
|
0
|
|
|
unless safeCall sub { sysopen ( FROMFILE, $fromName, "r" ) }; |
|
|
0
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$fromFileNum = fileno ( FROMFILE ); |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
die "flock ( $fromFileNum ): $!" unless flock ( FROMFILE, LOCK_SH ); |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my @stat; |
|
93
|
0
|
0
|
|
0
|
|
|
die "stat ( $fromFileNum ): $!" unless ( @stat = safeCall sub { stat ( FROMFILE ) } ); |
|
|
0
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
my $i = 0; while ( 1 ) { last unless -f ( $tmpToName = sprintf ( $tmpMask, $i++ ) ); } # ATT! XXX EINTR && -f ??? |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
die "sysopen ( $tmpToName, \"w\", $stat[2] ): $!" |
|
98
|
0
|
0
|
|
0
|
|
|
unless safeCall sub { sysopen ( TOFILE, "$tmpToName", "w", $stat[2] ) }; |
|
|
0
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$toFileNum = fileno ( TOFILE ); |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my ( $n, $buffer ); |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
while ( 1 ) |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
|
|
|
|
|
|
die "sysread ( $fromFileNum, buffer, $bufferSize): $!" |
|
107
|
0
|
0
|
|
0
|
|
|
unless defined ( $n = safeCall sub { sysread ( FROMFILE, $buffer, $bufferSize ) } ); |
|
|
0
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
last unless $n; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
die "syswrite ( $toFileNum, buffer, $n): $!" |
|
112
|
0
|
0
|
|
0
|
|
|
unless safeCall sub { syswrite ( TOFILE, $buffer, $n ) }; |
|
|
0
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
}; |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
if ( *FROMFILE ) |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
0
|
0
|
|
0
|
|
|
warn "close ( $fromFileNum ): $!" unless safeCall sub { close ( FROMFILE ) }; |
|
|
0
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
if ( *TOFILE ) |
|
122
|
|
|
|
|
|
|
{ |
|
123
|
0
|
0
|
|
0
|
|
|
warn "close ( $toFileNum ): $!" unless safeCall sub { close ( TOFILE ) }; |
|
|
0
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
if ( $@ ) |
|
125
|
|
|
|
|
|
|
{ |
|
126
|
0
|
0
|
|
0
|
|
|
warn "unlink( $tmpToName ): $!" unless safeCall sub { unlink ( $tmpToName ) }; |
|
|
0
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
die $@ if $@; |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
die "rename ( $tmpToName, $toName ): $!" |
|
133
|
|
|
|
|
|
|
unless rename ( $tmpToName, $toName ); |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
1; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub lowerKeys |
|
139
|
|
|
|
|
|
|
{ |
|
140
|
0
|
|
|
0
|
1
|
|
my $record = shift; |
|
141
|
0
|
|
|
|
|
|
my $lcRecord; |
|
142
|
0
|
|
|
|
|
|
foreach ( keys %$record ) |
|
143
|
|
|
|
|
|
|
{ |
|
144
|
0
|
|
|
|
|
|
$lcRecord->{ lc ( $_ ) } = $record->{ $_ }; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
0
|
|
|
|
|
|
$lcRecord; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub pathSubtract |
|
150
|
|
|
|
|
|
|
{ |
|
151
|
0
|
|
|
0
|
1
|
|
my @s1 = split '/', shift; my @s2 = split '/', shift; |
|
|
0
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $i = 0; for ( ; $s1 [ $i ] eq $s2 [ $i ] ; $i++ ) {} |
|
|
0
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
"../" x ( $#s1 - $i + 1 ) . join '/', @s2 [ $i .. $#s2 ]; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub strip |
|
157
|
|
|
|
|
|
|
{ |
|
158
|
0
|
|
|
0
|
0
|
|
my $line = shift; |
|
159
|
0
|
0
|
|
|
|
|
return undef unless defined $line; |
|
160
|
0
|
0
|
|
|
|
|
return $line unless $line; |
|
161
|
0
|
|
|
|
|
|
study $line; |
|
162
|
0
|
|
|
|
|
|
$line =~ s/^ +//g; |
|
163
|
0
|
|
|
|
|
|
$line =~ s/ +$//g; |
|
164
|
0
|
|
|
|
|
|
$line =~ s/^\t+//g; |
|
165
|
0
|
|
|
|
|
|
$line =~ s/\t+$//g; |
|
166
|
0
|
|
|
|
|
|
$line; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub decodeQueueCommand |
|
170
|
|
|
|
|
|
|
{ |
|
171
|
0
|
|
|
0
|
0
|
|
my $command = shift; |
|
172
|
0
|
|
|
|
|
|
my @params = map { my @result = split /=/, $_; |
|
|
0
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
|
$result[0] = '' unless defined $result[0]; |
|
174
|
0
|
0
|
0
|
|
|
|
$result[1] = '' if ( ( m/=/ ) && ( ! defined $result[1] ) ); |
|
175
|
0
|
|
|
|
|
|
@result; } split /:/, $command; |
|
176
|
0
|
|
|
|
|
|
@params; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
__END__ |