line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::SetSize; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2129
|
use File::Copy; |
|
1
|
|
|
|
|
5479
|
|
|
1
|
|
|
|
|
87
|
|
4
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
5
|
1
|
|
|
1
|
|
5
|
use vars qw(@ISA @EXPORT $VERSION); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
806
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@EXPORT = qw( setsize ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = "0.2"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my @NEW_FILE = (); |
19
|
|
|
|
|
|
|
my $file_name = ""; |
20
|
|
|
|
|
|
|
my $sizekeep = ""; |
21
|
|
|
|
|
|
|
my $size = ""; |
22
|
|
|
|
|
|
|
my $tmp = ""; |
23
|
|
|
|
|
|
|
my $size_limet = 50000; # array limit |
24
|
|
|
|
|
|
|
my $remove_amount = 0; |
25
|
|
|
|
|
|
|
my $size_after = 0; |
26
|
|
|
|
|
|
|
my $type = ""; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub setsize { |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
0
|
|
($file_name, $sizekeep) = @_ ; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
if ( $file_name eq "" ) { |
34
|
0
|
|
|
|
|
|
print "\n * No file *\n\n"; |
35
|
0
|
|
|
|
|
|
return 1; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
0
|
|
|
|
|
if ( $sizekeep eq "" ) { |
38
|
0
|
|
|
|
|
|
print "\n * No Size *\n\n"; |
39
|
0
|
|
|
|
|
|
return 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if (not -e $file_name) { |
43
|
0
|
|
|
|
|
|
print "\n * Can't find \"$file_name\" *\n\n"; |
44
|
0
|
|
|
|
|
|
return 1; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
0
|
|
|
|
|
if (-d $file_name) { |
47
|
0
|
|
|
|
|
|
print "\n * File is a directory *\n\n"; |
48
|
0
|
|
|
|
|
|
return 1; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
0
|
|
|
|
|
if (-z $file_name ) { |
51
|
0
|
|
|
|
|
|
print "$file_name is 0 size, can't go into negitve space\n\n"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
($size) = (stat($file_name)) [7]; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ( $size > $sizekeep ) { $remove_amount = ( $size - $sizekeep ) } |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
else { |
60
|
0
|
|
|
|
|
|
print "\n * File is already smaller than what you want it is $size Bytes *\n\n"; |
61
|
0
|
|
|
|
|
|
return 1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ( $size < $size_limet ) { |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
open(INFILE, "$file_name") or die "Error : Can not open $file_name"; |
67
|
0
|
|
|
|
|
|
seek (INFILE, $remove_amount, 0); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
while () { push @NEW_FILE, $_ } |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
close(INFILE); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
open (INFILE, ">$file_name"); |
73
|
0
|
|
|
|
|
|
print INFILE "@NEW_FILE"; |
74
|
0
|
|
|
|
|
|
close(INFILE); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
0
|
|
|
|
|
|
$tmp = "$file_name.tmp" ; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
open(INFILE, "$file_name") or die "Error : Can not open $file_name"; |
81
|
0
|
|
|
|
|
|
seek (INFILE, $remove_amount, 0); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
open(TEMPFILE, ">$tmp"); |
84
|
0
|
|
|
|
|
|
while () { |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
print TEMPFILE $_ ; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
close(TEMPFILE); |
90
|
0
|
|
|
|
|
|
close(INFILE); |
91
|
0
|
|
|
|
|
|
print "$tmp .. $file_name\n"; |
92
|
0
|
0
|
|
|
|
|
copy("$tmp", "$file_name") or die "move failed: $!"; |
93
|
0
|
|
|
|
|
|
unlink($tmp); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
($size_after) = (stat($file_name)) [7]; |
98
|
0
|
|
|
|
|
|
print "$file_name type $type, was $size, set to $size_after bytes\n"; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
}; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |