grablines: raise PermissionDenied if appropriate
authorZac Medico <zmedico@gentoo.org>
Fri, 1 Jun 2012 21:30:37 +0000 (14:30 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 1 Jun 2012 21:30:37 +0000 (14:30 -0700)
pym/portage/util/__init__.py

index 2e0a32bb0e807816785ba3a38f27a31349cf60f9..4ffd599b838666931ce3291ed9744f650ca46cae 100644 (file)
@@ -469,7 +469,15 @@ def grablines(myfilename, recursive=0, remember_source_file=False):
        if recursive and os.path.isdir(myfilename):
                if os.path.basename(myfilename) in _ignorecvs_dirs:
                        return mylines
-               dirlist = os.listdir(myfilename)
+               try:
+                       dirlist = os.listdir(myfilename)
+               except OSError as e:
+                       if e.errno == PermissionDenied.errno:
+                               raise PermissionDenied(myfilename)
+                       elif e.errno in (errno.ENOENT, errno.ESTALE):
+                               return mylines
+                       else:
+                               raise
                dirlist.sort()
                for f in dirlist:
                        if not f.startswith(".") and not f.endswith("~"):
@@ -488,7 +496,10 @@ def grablines(myfilename, recursive=0, remember_source_file=False):
                except IOError as e:
                        if e.errno == PermissionDenied.errno:
                                raise PermissionDenied(myfilename)
-                       pass
+                       elif e.errno in (errno.ENOENT, errno.ESTALE):
+                               pass
+                       else:
+                               raise
        return mylines
 
 def writedict(mydict,myfilename,writekey=True):