File-Sticker
view release on metacpan or search on metacpan
lib/File/Sticker.pm view on Meta::CPAN
sub missing_files {
my $self = shift;
my @missing_files = ();
my @files = @{$self->{db}->get_all_files()};
foreach my $file (@files)
{
say STDERR "checking $file" if $self->{verbose} > 2;
if (!-r $file and !-d $file)
{
push @missing_files, $file;
}
}
return \@missing_files;
} # missing_files
=head2 overlooked_files
Check through the database to see which of the given files are not in the database.
my $files = $sticker->overlooked_files(@files);
=cut
sub overlooked_files {
my $self = shift;
my @files = @_;
my @overlooked = ();
foreach my $file (@files)
{
my $id = $self->{db}->get_file_id($file);
if (!$id)
{
push @overlooked, $file;
}
}
return \@overlooked;
} # overlooked_files
=head2 list_tags
List the faceted-tags from the info table in the database.
my @tags = @{$sticker->list_tags()};
=cut
sub list_tags {
my $self = shift;
my $tags = $self->{db}->get_all_tags();
return $tags;
} # list_tags
=head2 update_db
Add/Update the given files into the database.
$sticker->update_db(@files);
=cut
sub update_db {
my $self = shift;
my @files = @_;
my $transaction_on = 0;
my $num_trans = 0;
foreach my $filename (@files)
{
say $filename if !$self->{quiet};
if (!$transaction_on)
{
$self->{db}->start_transaction();
$transaction_on = 1;
$num_trans = 0;
}
my $meta = $self->read_meta(filename=>$filename,read_all=>0);
my $scribe = $self->_get_scribe($filename);
# If there are desired fields which are derivable
# but which are not set in the file itself,
# derive them, so they can be added to the meta
my $derived = $self->derive_values(filename=>$filename,meta=>$meta);
my $readonly_fields = $scribe->readonly_fields();
foreach my $field (@{$self->{field_order}})
{
if (!$meta->{$field} and defined $derived->{$field})
{
$meta->{$field} = $derived->{$field};
}
# If it is a readonly field, which is also derived,
# (such as filesize) then it needs to overwrite any old value.
if (exists $readonly_fields->{$field}
and defined $readonly_fields->{$field}
and defined $derived->{$field})
{
$meta->{$field} = $derived->{$field};
}
}
$self->{db}->add_meta_to_db($filename,%{$meta});
# do the commits in bursts
$num_trans++;
if ($transaction_on and $num_trans > 100)
{
$self->{db}->commit();
$transaction_on = 0;
$num_trans = 0;
say " " if $self->{verbose};
}
}
$self->{db}->commit();
} # update_db
=head2 delete_file_from_db
Delete the given file from the database.
$sticker->delete_file_from_db($filename);
=cut
( run in 0.456 second using v1.01-cache-2.11-cpan-e1769b4cff6 )