Make RecursiveFileLoader skip hidden directories, and only use a single stat
authorZac Medico <zmedico@gentoo.org>
Thu, 30 Apr 2009 07:00:12 +0000 (07:00 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 30 Apr 2009 07:00:12 +0000 (07:00 -0000)
call to check for existence and file type. (trunk r13298)

svn path=/main/branches/2.1.6/; revision=13469

pym/portage/env/loaders.py

index e031ed60f80a78933cc5793cf89f59ac4cdabb5b..400797c0c4d2d1c61fdc8cb2dd87f5009c400dd2 100644 (file)
@@ -4,6 +4,7 @@
 # $Id$
 
 import os
+import stat
 
 class LoaderError(Exception):
        
@@ -36,14 +37,18 @@ def RecursiveFileLoader(filename):
        @rtype: list
        @returns: List of files to process
        """
-       if not os.path.exists(filename):
+       try:
+               st = os.stat(filename)
+       except OSError:
                return
-       elif os.path.isdir(filename):
+       if stat.S_ISDIR(st.st_mode):
                for root, dirs, files in os.walk(filename):
-                       if 'CVS' in dirs:
-                               dirs.remove('CVS')
-                       files = [f for f in files if not f.startswith('.') and not f.endswith('~')]
+                       for d in list(dirs):
+                               if d[:1] == '.' or d == 'CVS':
+                                       dirs.remove(d)
                        for f in files:
+                               if f[:1] == '.' or f[-1:] == '~':
+                                       continue
                                yield os.path.join(root, f)
        else:
                yield filename