line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LEOCHARRE::BogusFile; |
2
|
1
|
|
|
1
|
|
23367
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
3
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @EXPORT_OK %EXPORT_TAGS @ISA @CHARS $CHARLAST $MAXLENGTH); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
112
|
|
4
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
46
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
703
|
|
6
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)/g; |
7
|
|
|
|
|
|
|
@ISA = qw/Exporter/; |
8
|
|
|
|
|
|
|
@EXPORT_OK = qw(make_bogus_file arg2bytes); |
9
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => \@EXPORT_OK ); |
10
|
|
|
|
|
|
|
@CHARS = (0 .. 9); |
11
|
|
|
|
|
|
|
$CHARLAST = scalar @CHARS; |
12
|
|
|
|
|
|
|
$MAXLENGTH = 100000; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub make_bogus_file { |
18
|
4
|
|
|
4
|
1
|
7853
|
my ($path, $size_arg) = @_; |
19
|
4
|
50
|
|
|
|
33
|
$path or confess("missing path argument"); |
20
|
4
|
50
|
0
|
|
|
49
|
(Carp::cluck("$path already on disk") and return) if -e $path; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
4
|
100
|
|
|
|
54
|
my $size = $size_arg ? arg2bytes($size_arg) : _randlength(); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# size should be in k? |
27
|
|
|
|
|
|
|
|
28
|
4
|
50
|
0
|
|
|
422
|
open(F,'>',$path) or Carp::Cluck("cant open for writing '$path', $!") and return; |
29
|
4
|
|
|
|
|
13
|
print F _randstring($size); |
30
|
4
|
|
|
|
|
177
|
close F; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# cant return size here so simply.. |
33
|
|
|
|
|
|
|
# it may not have been defined.. |
34
|
4
|
50
|
|
|
|
46
|
$size || (stat($path))[7]; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
68
|
sub _randlength { int( rand($MAXLENGTH) + 1 ) } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _randstring { |
41
|
4
|
|
|
4
|
|
8
|
my $length = shift; |
42
|
4
|
|
33
|
|
|
14
|
$length ||= int( rand($MAXLENGTH) + 1 ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#print STDERR "randstring() length: $length\n" if $DEBUG; |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
8
|
my $string; |
47
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
18
|
for ( 0 .. ($length - 1)){ |
49
|
23545
|
|
|
|
|
60475
|
$string.=$CHARS[int(rand($CHARLAST))]; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
394
|
$string; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub arg2bytes { |
57
|
17
|
50
|
|
17
|
1
|
6076
|
defined $_[0] or confess("missing arg"); |
58
|
17
|
100
|
|
|
|
101
|
$_[0]=~/^\d+$/ and return $_[0]; |
59
|
|
|
|
|
|
|
|
60
|
13
|
|
|
|
|
17
|
my $totalbytes = $_[0]; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#print STDERR "\n\ninitial bytes arg at $totalbytes\n" if $DEBUG; |
64
|
13
|
100
|
|
|
|
546
|
$totalbytes=~/^\d/ or confess("invalid size ammount spec $totalbytes"); |
65
|
|
|
|
|
|
|
|
66
|
12
|
|
|
|
|
73
|
my %unit = ( |
67
|
|
|
|
|
|
|
B => 1, # in bytes |
68
|
|
|
|
|
|
|
K => 1024, # kilobytes |
69
|
|
|
|
|
|
|
M => ( 1024 * 1024 ), # megabytes |
70
|
|
|
|
|
|
|
G => ( 1024 * 1024 * 1024 ), # gigabytes - too big.. ?? |
71
|
|
|
|
|
|
|
); |
72
|
12
|
100
|
|
|
|
67
|
if($totalbytes=~s/([BKMG]{1}).*$//i){ |
73
|
11
|
|
|
|
|
42
|
my $unit = $unit{uc($1)}; |
74
|
|
|
|
|
|
|
#print STDERR " [$totalbytes] "; |
75
|
11
|
|
|
|
|
30
|
$totalbytes = int ($totalbytes * $unit); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#printf STDERR "totalbytes [unit %s] resolved to total bytes: $totalbytes\n", $unit{uc($1)}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
12
|
100
|
66
|
|
|
105
|
$totalbytes and $totalbytes=~/^\d+$/ or die("invalid size resolved: $totalbytes"); |
81
|
|
|
|
|
|
|
|
82
|
11
|
|
|
|
|
52
|
$totalbytes; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |