[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Looping folders



|I was helping someone do some MacPerl coding and we were recursing through
|directories.  The program ran out of memory because it turned out they had
|aliased a folder (somehow) to point back at the top level directory.  I
|corrected this by just always comparing the new folder against a list of
|folders already gone through.  Is there a better way to do this?

On a Mac, aliases are considered symbolic links by the file tests. To
see what this mean, assume $file is the path to an alias to a directory.
Then:

-d $file; # => true
-l $file; # => true

stat $file; -d _; # => true
stat $file; -l _; # => error

lstat $file; -d _; # => false
lstat $file; -l _; # => true

What this means is that if you're passing a path to the file tests,
you only want to recurse when -d $file && !-l $file. If you're doing
a stat and passing _ to the file tests, you only want to recurse when
-d _ && !-l _. If you're doing an lstat, you can recurse on just -d _.

Looking at File::Find, it does an lstat and then recurses on -d _,
so it should work fine in the face of aliases or symbolic links forming
loops in the file system.

Brian

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch