5 # Given a list of directories, report any bogus symbolic links contained
6 # anywhere in those subtrees. A bogus symbolic link is one that cannot
7 # be resolved because it points to a nonexistent or otherwise
8 # unresolvable file. Do *not* use an external find executable.
9 # Directories may be very very deep. Print a warning immediately if the
10 # system you're running on doesn't support symbolic links.
12 # This implementation:
13 # - takes one optional argument, using the current directory as default
14 # - uses chdir to increase performance
15 # - sorts the names per directory
16 # - prints output lines of the form "path1 -> path2" as it goes
17 # - prints error messages about directories it can't list or chdir into
25 # Note: can't test for presence of lstat -- it's always there
27 except AttributeError:
28 print "This system doesn't have symbolic links"
36 if prefix
[-1:] != '/': prefix
= prefix
+ '/'
37 reportboguslinks(prefix
)
41 def reportboguslinks(prefix
):
43 names
= os
.listdir('.')
45 print "%s%s: can't list: %s" % (prefix
, '.', msg
)
49 if name
== os
.curdir
or name
== os
.pardir
:
52 mode
= os
.lstat(name
)[ST_MODE
]
54 print "%s%s: can't stat: %s" % (prefix
, name
, msg
)
60 print "%s%s -> %s" % \
61 (prefix
, name
, os
.readlink(name
))
66 print "%s%s: can't chdir: %s" % \
70 reportboguslinks(prefix
+ name
+ '/')