Reputation: 1553
I'm using Perl's module File::Find to traverse across a directory.
This directory is an NFS share which has the directory .snapshot.
In this folder there's a snapshot of yesterdays file structure and thus it has directories with the same name in the result.
I therefore get the following error:
[folder_in_which_find_is_executed].snapshot/sv_daily.0 encountered a second time at /usr/lib/perl5/5.8.8/File/Find.pm line 566.
Is there a way to prevent this from happening e.g. by removing the duplicate entry?
This is the code sub that executes the find:
sub process()
{
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat $_;
my $type = (-f _ ? 'f' : (-d _ ? 'd' : '*'));
my ($md5sum);
if (!defined $dev)
{
if (-l $_)
{
die "Broken symbolic link: $File::Find::name";
} else {
die "Error processing $type '$File::Find::name'";
}
}
my $name = $File::Find::name;
$name =~ s|^\.\/?||;
if ($name ne '')
{
$db->{$name} = {
name => $name,
mode => sprintf("%04o", $mode & 07777),
user_id => $uid,
group_id => $gid,
last_modified => $mtime,
type => $type
};
if ($type eq 'f')
{
$db->{$name}->{size} = $size;
$db->{$name}->{inode} = $ino;
$md5sum = SumForEntry($name, $_);
$db->{$name}->{md5sum} = $md5sum;
}
}
}
The following line executes this sub:
find({ wanted => \&process, follow => 1}, '.');
Can somebody please help me?
Upvotes: 2
Views: 1268
Reputation: 753625
The 'wanted' function can tell File::Find
to prune its search:
The function may set $File::Find::prune to prune the tree unless bydepth was specified.
On entry to the snapshot directory, set the prune variable to prevent further processing of it.
Upvotes: 1