I have this basic Perl script that should traverse my directory tree recursively.
#!/usr/bin/perl -w
use strict;
use File::Find;
my $dir = '/mnt/drawings';
find(\&process_file, $dir);
sub process_file
{
print("$File::Find::name\n");
}
But when I run it on my CentOS system it only prints the first level under '/mnt/drawings' around 20 directory. But when I run the same script on my FreeBSD system, it prints every file tens of thousands...
What am I missing on my CentOS system?
Update:
Both systems are mounting the same data on FreeNAS. If I run ls -lR
I can see all the files: Here's the first few folders:
drwxr-xr-x. 2 root root 0 Mar 25 2011 2008dwgs
drwxr-xr-x. 2 root root 0 Nov 19 2015 2009dwgs
drwxr-xr-x. 2 root root 0 Oct 21 2016 2010dwgs
drwxr-xr-x. 2 root root 0 Jun 16 2014 2011dwgs
drwxr-xr-x. 2 root root 0 May 14 17:58 2012dwgs
drwxr-xr-x. 2 root root 0 Nov 29 2016 2013dwgs
drwxr-xr-x. 2 root root 0 Aug 8 2018 2014dwgs
drwxr-xr-x. 2 root root 0 Apr 1 18:11 2015dwgs
drwxr-xr-x. 2 root root 0 Jul 28 21:55 2016dwgs
drwxr-xr-x. 2 root root 0 Jun 17 12:39 2017dwgs
drwxr-xr-x. 2 root root 0 Jun 11 10:27 2018dwgs
drwxr-xr-x. 2 root root 0 Jul 26 15:40 2019dwgs
And here it is inside the 2008dwgs folder:
./2008dwgs:
total 0
drwxr-xr-x. 2 root root 0 May 20 2014 08002-01
drwxr-xr-x. 2 root root 0 Apr 9 2011 08003
drwxr-xr-x. 2 root root 0 May 28 2013 08008
drwxr-xr-x. 2 root root 0 Nov 10 2014 08009
drwxr-xr-x. 2 root root 0 Jan 23 2008 08011
And inside the 08002-01 folder:
./2008dwgs/08002-01:
total 0
drwxr-xr-x. 2 root root 0 May 20 2014 ArchDwgs
drwxr-xr-x. 2 root root 0 Aug 28 2014 BASES
drwxr-xr-x. 2 root root 0 May 20 2014 FinalPDF
drwxr-xr-x. 2 root root 0 Oct 13 2009 Fonts
drwxr-xr-x. 2 root root 0 Aug 27 2014 issued
drwxr-xr-x. 2 root root 0 May 19 2011 NPS Reference
drwxr-xr-x. 2 root root 0 Oct 13 2009 Pen Settings
drwxr-xr-x. 2 root root 0 Aug 27 2014 Received
drwxr-xr-x. 2 root root 0 Dec 8 2009 SketchUp
drwxr-xr-x. 2 root root 0 Jun 24 03:05 Struct
I think I've found the bug. Perlbug 133673 .
I looked at the code in Find.pm and I see that it automatically avoids using the number of links to a directory when
stat
on the directory returns less than 2 for nlink. Unfortunately, it appears that directories on the NAS return 2 as the number of links for all directories.
That's what your network filesystem is doing.
The fix is in Perl 5.30.0. You can upgrade, or you can set local $File::Find::dont_use_nlink = 1;
to ignore the filesystem nlink.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.