line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FileMetadata::Miner::Stat;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
16456
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
956
|
use utf8;
|
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
38
|
use POSIX qw(strftime);
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
95
|
use Fcntl ':mode';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
941
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0';
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new {
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
1
|
127
|
my $self = {};
|
13
|
4
|
|
|
|
|
12
|
bless $self, shift;
|
14
|
4
|
|
|
|
|
7
|
my $config = shift;
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Set the size units
|
17
|
|
|
|
|
|
|
|
18
|
4
|
|
|
|
|
15
|
$self->{'size_format'} = '';
|
19
|
4
|
100
|
|
|
|
22
|
if (defined $config->{'size'}) {
|
20
|
3
|
100
|
|
|
|
36
|
die "Invalid 'size' format" unless $config->{'size'} =~ /^(MB|KB|bytes)$/;
|
21
|
2
|
|
|
|
|
4
|
$self->{'size_format'} = $config->{'size'};
|
22
|
|
|
|
|
|
|
}
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Set the format for date
|
25
|
|
|
|
|
|
|
|
26
|
3
|
50
|
|
|
|
12
|
if (defined $config->{'date'}) {
|
27
|
0
|
|
|
|
|
0
|
$self->{'time_format'} = $config->{'date'};
|
28
|
|
|
|
|
|
|
} else {
|
29
|
3
|
|
|
|
|
7
|
$self->{'time_format'} = '%T-%D';
|
30
|
|
|
|
|
|
|
}
|
31
|
3
|
|
|
|
|
9
|
return $self;
|
32
|
|
|
|
|
|
|
}
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub mine {
|
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
4
|
1
|
116
|
my ($self, $path, $meta) = @_;
|
37
|
4
|
|
|
|
|
66
|
my $result = stat ($path);
|
38
|
4
|
|
|
|
|
8
|
my $name = ref ($self); # For efficiency
|
39
|
|
|
|
|
|
|
|
40
|
4
|
100
|
|
|
|
15
|
return $result unless $result; # Return on error
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Generate size in the right format
|
43
|
3
|
|
|
|
|
8
|
my $size = (stat (_))[7];
|
44
|
|
|
|
|
|
|
|
45
|
3
|
100
|
|
|
|
18
|
if ($self->{'size_format'} eq 'MB') {
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
46
|
1
|
|
|
|
|
11
|
$meta->{"$name"."::size"} = $size/ (1024*1024) . " MB";
|
47
|
|
|
|
|
|
|
} elsif ($self->{'size_format'} eq 'KB') {
|
48
|
1
|
|
|
|
|
20
|
$meta->{"$name"."::size"} = $size/ (1024) . " KB";
|
49
|
|
|
|
|
|
|
} elsif ($self->{'size_format'} eq 'bytes') {
|
50
|
0
|
|
|
|
|
0
|
$meta->{"$name"."::size"} = "$size bytes";
|
51
|
|
|
|
|
|
|
} else {
|
52
|
1
|
|
|
|
|
6
|
$meta->{"$name"."::size"} = $size;
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Generate times in the right format
|
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
291
|
my $time_str = strftime ($self->{'time_format'},
|
58
|
|
|
|
|
|
|
localtime ((stat (_))[9]));
|
59
|
3
|
|
|
|
|
16
|
$meta->{"$name"."::mtime"} = $time_str;
|
60
|
3
|
|
|
|
|
173
|
$time_str = strftime ($self->{'time_format'},
|
61
|
|
|
|
|
|
|
localtime ((stat (_))[10]));
|
62
|
3
|
|
|
|
|
16
|
$meta->{"$name"."::ctime"} = $time_str;
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Figure out the type of file
|
65
|
|
|
|
|
|
|
|
66
|
3
|
50
|
|
|
|
16
|
if (S_ISREG ((stat (_))[2])) {
|
|
|
0
|
|
|
|
|
|
67
|
3
|
|
|
|
|
9
|
$meta->{"$name\:\:type"} = 'REG'
|
68
|
|
|
|
|
|
|
} elsif (S_ISDIR ((stat (_))[2])) {
|
69
|
0
|
|
|
|
|
0
|
$meta->{"$name\:\:type"} = 'DIR'
|
70
|
|
|
|
|
|
|
} else {
|
71
|
0
|
|
|
|
|
0
|
$meta->{"$name\:\:type"} = 'OTHER'
|
72
|
|
|
|
|
|
|
}
|
73
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
15
|
return $result;
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1;
|
78
|
|
|
|
|
|
|
__END__
|