[Tutor] islink() in macpath and directory walk

Christopher Smith csmith@blakeschool.org
Thu, 14 Mar 2002 16:37:06 -0600


I was using the walk function to go through directories and change
modification times on files which, because of a daylight savings issue are
1 hour different than a backup set that I have.  I've run into two issues:

1) I don't want to follow aliases to other folders--I just want to update
files that are physically in the root folder and its subfolders.  So it
seems that I must remove aliases in the list of files that is passed to
the function that is called as walk() takes place.  I noticed that in
macpath there is an islink() function that says

def islink(s):
    """Return true if the pathname refers to a symbolic link.
    Always false on the Mac, until we understand Aliases."""

   return 0

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]

The [2]th value is 1 or 0 depending on whether or not the file specified
by s is an alias.

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.)

/c