On Thursday 19 February 2004 18:42, you wrote:
> Trent Shipley wrote:
> > What it means is that you can't write a naive recursive tree traversal
> > program when working with directories. (Eg. I want to write a PHP
> > program that gives me a flat alphabetic index for an entire web site.)
> >
> > Any idea about how to build a hash of i-nodes so that you traverse a
> > cycle in the directory structure one-and-only one time?
> >
> > (It's an elemental data structure problem--how to visit each node in a
> > cyclic graph one-and-only one time.)
> >
> > On Thursday 2004-02-19 16:17, Joe Toon wrote:
> >>I did the following for #1:
> >>
> >>$ ln -s filea fileb
> >>$ ln -s fileb filea
> >>$ cat filea # symlink to a symlink
> >>cat: files: Too many levels of symbolic links
> >>
> >>Then I did the following for #2:
> >>
> >>$ mkdir test
> >>$ cd test
> >>$ ln -s ../test dirsym
> >>$ cd dirsym
> >>
> >>This allows me to enter dirsym indefinitely -- i could see something
> >>getting hung up over this if it followed the sym links..
> >>
> >>I would imagine this would be true for the final scenario as well.
> >>
> >>Trent Shipley wrote:
> >>>Is a *nix file system guranteed to be acyclic?
> >>>
> >>>That is no:
> >>>
> >>>File-a links to file-b and file-b links to file-a
> >>>
> >>>And more important
> >>>
> >>>No directory-a contains link-b where link-b points to directory-a.
> >>>
> >>>Also
> >>>
> >>>Directory-a contains no link-b to directory-c where directory-c contains
> >>>link-d to directory-a.
>
> That might be why a lot of things that do need to traverse a directory tree
> have options like to not follow symbolic links. They may miss something
> because of that option, but they won't get caught up in a self-recursive
> loop. ---------------------------------------------------
Good suggestion. Another way (I did this in a C++ routine) is to keep a list
of all the directory inodes you process. Every time you open a new one, you
check it against the list. If it matches anything in the list, you skip that
one. Of course this would only work for traversing a reasonbly sized file
tree.
Vaughn
> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss