File-Information
view release on metacpan or search on metacpan
lib/File/Information/Inode.pm view on Meta::CPAN
$pv->{current}{tagpool_file_write_mode} = {raw => $tag};
} elsif ($info->{for} eq 'mediatype') {
$pv->{current}{tagpool_file_mediatype} = {raw => $info->{mediatype}, ise => $tag};
} elsif ($info->{for} eq 'finalmode') {
$pv->{current}{tagpool_file_finalmode} = {raw => $tag};
} else {
croak 'BUG!';
}
push(@next, @{$info->{implies}}) if defined $info->{implies};
}
}
}
# Media Type:
{
my $value = readlink(File::Spec->catfile($in_pool, qw(cache mimetype file), $uuid));
if (defined($value) && length($value)) {
$pv->{current}{tagpool_file_mediatype} //= {raw => $value};
}
}
# Write mode:
{
my $value = readlink(File::Spec->catfile($in_pool, qw(cache write-mode file), $uuid));
if (defined($value) && length($value)) {
$pv->{current}{tagpool_file_write_mode} //= {raw => $value};
}
}
{
my $value = File::Spec->catfile($in_pool, qw(cache thumbnail file), $uuid.'.png');
my @c_stat = stat($value);
if (scalar(@c_stat)) {
if ($stat[9] < $c_stat[9]) {
$pv->{current}{tagpool_file_thumbnail} //= {raw => $value};
}
}
}
}
}
}
sub _load_magic {
my ($self) = @_;
my $pv = ($self->{properties_values} //= {})->{current} //= {};
my $data;
my $media_type;
return if $self->{_loaded_magic};
$self->{_loaded_magic} = 1;
$data = eval {$self->peek};
return unless defined $data;
if (substr($data, 0, 22) eq '<!DOCTYPE HTML PUBLIC ' || substr($data, 0, 22) eq '<!DOCTYPE html PUBLIC ' || substr($data, 0, 22) eq '<!DOCTYPE HTML SYSTEM ' || uc(substr($data, 0, 15)) eq '<!DOCTYPE HTML>' ||
lc(substr($data, 0, 6)) eq '<html>' ||
$data =~ /^<\?xml version="1\.0" encoding="utf-8"\?>\r?\n?<\!DOCTYPE html PUBLIC /) {
$media_type = 'text/html';
} elsif ($data =~ /^<\?xml version="1\.0" encoding="UTF-8"\?>\s*<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1\.0"[^>]+office:mimetype="(application\/vnd\.oasis\.opendocument\.(?:text|spreadsheet|presentation|graphi...
$media_type = $1;
} elsif ($data =~ /^PK\003\004....\0\0................\010\0\0\0mimetype(application\/vnd\.oasis\.opendocument\.(?:text|spreadsheet|presentation|graphics|chart|formula|image|text-master|(?:text|spreadsheet|presentation|graphics)-template))PK\003\...
$media_type = $1;
} elsif (substr($data, 0, 8) eq "!<arch>\n") {
if ($data =~ /^!<arch>\ndebian-binary [0-9 ]{12}0 0 [0-7 ]{8}[0-9] `\n/) {
$media_type = 'application/vnd.debian.binary-package';
} else {
$media_type = 'application/x-archive';
}
} elsif ($data =~ /^!!ValueFile ([0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})\s+(!null|[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}|[0-2](?:\.(?:0|[1-9][0-9]*))+|[a-zA-Z][a-zA-Z0-9\+\.\-]+[^\s%]+)[\s\r\n]/) {
my ($version, $format) = ($1, $2);
$pv->{magic_valuefile_version} = {raw => $version};
$pv->{magic_valuefile_format} = {raw => $format} unless $format =~ /^!/;
} elsif ($data =~ /^\0([\x07-\x3f])VM\x0d\x0a\xc0\x0a/ && (ord($1) & 07) == 07) {
$media_type = 'application/vnd.sirtx.vmv0';
} elsif ($data =~ /^RIFF.{4}WEBPVP8/) {
$media_type = 'image/webp';
} else {
foreach my $magic (sort {length($b) <=> length($a)} keys %_magic_map) {
if (substr($data, 0, length($magic)) eq $magic) {
$media_type = $_magic_map{$magic};
last;
}
}
}
$pv->{magic_mediatype} = {raw => $media_type} if defined $media_type;
}
sub _load_db {
my ($self, $key, %opts) = @_;
my $pv = ($self->{properties_values} //= {})->{current} //= {};
return if $self->{_loaded_db};
$self->{_loaded_db} = 1;
if (defined(my $db = eval { $self->instance->db })) {
eval {
my $inode = $self->get('st_ino', as => 'raw');
my $fs = $self->filesystem->get('ise', as => 'Data::TagDB::Tag');
my $inode_number = $db->tag_by_id(uuid => 'd2526d8b-25fa-4584-806b-67277c01c0db');
my $also_on_filesystem = $db->tag_by_id(uuid => 'cd5bfb11-620b-4cce-92bd-85b7d010f070');
my $wk = $db->wk;
my $metadata = $db->metadata(relation => $wk->also_shares_identifier, type => $inode_number, data_raw => $inode);
my $res;
#warn sprintf('inode=%s, inode_number=%s, fs=%s', $inode, $inode_number, $fs);
$metadata->foreach(sub {
my ($entry) = @_;
my $fs_relation = $db->relation(tag => $entry->tag, relation => $also_on_filesystem, related => $fs)->one;
$res = $entry->tag;
#warn $fs_relation;
});
$pv->{db_inode_tag} = {raw => $res} if defined $res;
};
}
}
sub _load_redirect {
my ($self, $key, %opts) = @_;
my $info = $self->{properties}{$key};
( run in 1.571 second using v1.01-cache-2.11-cpan-39bf76dae61 )