Perl 文件::查找重复名称
我正在使用 Perl 的模块 File::Find 来遍历目录。 该目录是一个 NFS 共享,其中包含目录 .snapshot。 在此文件夹中,有昨天文件结构的快照,因此结果中具有相同名称的目录。 因此,我收到以下错误:
[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.
有没有办法防止这种情况发生,例如通过删除重复的条目?
这是执行查找的代码子程序:
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;
}
}
}
以下行执行此子程序:
find({ wanted => \&process, follow => 1}, '.');
有人可以帮助我吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
'wanted' 函数可以告诉
File::Find
修剪其搜索:进入快照目录时,设置 prune 变量以防止对其进行进一步处理。
The 'wanted' function can tell
File::Find
to prune its search:On entry to the snapshot directory, set the prune variable to prevent further processing of it.