[Pythonmac-SIG] islink() in macpath and directory walk
Adam Eijdenberg
adam@switchedonsoftware.com
Fri, 15 Mar 2002 10:55:25 +1100
> Maybe this is just a function that hasn't been used by others and has
> thus
> never been updated...is there any reason not to have the function do the
> following return?
>
> return macfs.ResolveAliasFile(s)[2]
Can't answer that one for you, but...
> 2) If I *do* want to follow aliases, I don't want to get trapped in an
> infinite loop caused when two folders contain aliases of each other. Is
> there a clever "loop detection" algorithm for this short of keeping
> track
> of every folder visited? what is this condition called? (I checked
> ASPN
> with "loop detection", "walk detection", etc...without a lot of
> success.)
This is more of a general programming question. One method I have used
for similar projects, is start with two empty lists, say TO_PROCESS and
DONE.
Add your first job (or in this case "root" folder) to TO_PROCESS and to
DONE and then run something like the following:
while len (TO_PROCESS) > 0:
job = TO_PROCESS.pop ()
... process job, possibly getting new child jobs and adding them as
below ....
if not (newChildJob in DONE):
TO_PROCESS.append (newChildJob)
DONE.append (newChildJob)
Not sure what you would exactly call this condition, but solving it with
queues is usually fairly simple.
Hope that helps,
Adam