fix bug 398103 to properly delete broken symlinks and not abort.
authorBrian Dolbec <dolsen@gentoo.org>
Sun, 22 Jan 2012 17:48:36 +0000 (09:48 -0800)
committerBrian Dolbec <dolsen@gentoo.org>
Sun, 22 Jan 2012 17:48:36 +0000 (09:48 -0800)
pym/gentoolkit/eclean/clean.py

index b2cc562d2f74a8cb3286eb700035e2dec854353e..fd599761e72216554039a81d9b72cd052e2f2cfd 100644 (file)
@@ -125,10 +125,22 @@ class CleanUp(object):
                        try:
                                statinfo = os.stat(file_)
                        except EnvironmentError as er:
-                               print( pp.error(
-                                       "Could not get stat info for:" + file_), file=sys.stderr)
-                               print( pp.error(
-                                       "Error: %s" %str(er)), file=sys.stderr)
+                               if not os.path.exists(os.readlink(file_)):
+                                       try:
+                                               os.remove(file_)
+                                               print( pp.error(
+                                                       "Removed broken symbolic link " + file_), file=sys.stderr)
+                                               break
+                                       except EnvironmentError as er:
+                                               print( pp.error(
+                                                       "Error deleting broken symbolic link " + file_), file=sys.stderr)
+                                               print( pp.error("Error: %s" %str(er)), file=sys.stderr)
+                                               break
+                               else:
+                                       print( pp.error(
+                                               "Could not get stat info for:" + file_), file=sys.stderr)
+                                       print( pp.error(
+                                               "Error: %s" %str(er)), file=sys.stderr)
                        if self.controller(statinfo.st_size, key, file_, file_type):
                                # ... try to delete it.
                                try: