Commits

Steven Knight  committed 48b7ed7

More efficient checking for on-disk file entries.

  • Participants
  • Parent commits 7bbdbd9

Comments (0)

Files changed (4)

File src/CHANGES.txt

   - Add the +Z option by default when compiling shared objects on
     HP-UX.
 
+  - Check for whether files exist on disk by listing the directory
+    contents, not calling os.path.exists() file by file.  This is
+    somewhat more efficient in general, and may be significantly
+    more efficient on Windows.
+
   From Chen Lee:
 
   - Handle Visual Studio project and solution files in Unicode.

File src/engine/SCons/Node/FS.py

     pass
 
 def do_diskcheck_rcs(node, name):
-    rcspath = 'RCS' + os.sep + name+',v'
-    return node.entry_exists_on_disk(rcspath)
+    try:
+        rcs_dir = node.rcs_dir
+    except AttributeError:
+        rcs_dir = node.rcs_dir = node.Dir('RCS')
+    return rcs_dir.entry_exists_on_disk(name+',v')
 
 def ignore_diskcheck_rcs(node, name):
     return None
 
 def do_diskcheck_sccs(node, name):
-    sccspath = 'SCCS' + os.sep + 's.'+name
-    return node.entry_exists_on_disk(sccspath)
+    try:
+        sccs_dir = node.sccs_dir
+    except AttributeError:
+        sccs_dir = node.sccs_dir = node.Dir('SCCS')
+    return sccs_dir.entry_exists_on_disk('s.'+name)
 
 def ignore_diskcheck_sccs(node, name):
     return None
 
     def getmtime(self):
         st = self.stat()
-        if st:
-            return self.stat()[stat.ST_MTIME]
-        else:
-            return None
+        if st: return st[stat.ST_MTIME]
+        else: return None
 
     def getsize(self):
         st = self.stat()
-        if st:
-            return self.stat()[stat.ST_SIZE]
-        else:
-            return None
+        if st: return st[stat.ST_SIZE]
+        else: return None
 
     def isdir(self):
         st = self.stat()
 
     def entry_exists_on_disk(self, name):
         """__cacheable__"""
-        return self.fs.exists(self.entry_abspath(name))
+        try:
+            d = self.on_disk_entries
+        except AttributeError:
+            d = {}
+            try:
+                entries = os.listdir(self.abspath)
+            except OSError:
+                pass
+            else:
+                for entry in entries:
+                    d[entry] = 1
+            self.on_disk_entries = d
+        return d.has_key(name)
 
     def srcdir_list(self):
         """__cacheable__"""

File src/engine/SCons/Node/FSTests.py

         r = fs.Rfindalldirs(['d1', d2], fs.Top)
         assert r == [d1, rep1_d1, rep2_d1, rep3_d1, d2], map(str, r)
 
-    def test_rexists(self):
+    def tttest_rexists(self):
         """Test the Entry.rexists() method"""
         fs = self.fs
         test = self.test
 
         test.write([self.rep1, 'f2'], "")
+        test.write([self.rep2, "i_exist"], "\n")
+        test.write(["work", "i_exist_too"], "\n")
 
         fs.BuildDir('build', '.')
 
         f = fs.File(test.workpath("work", "i_do_not_exist"))
         assert not f.rexists()
 
-        test.write([self.rep2, "i_exist"], "\n")
         f = fs.File(test.workpath("work", "i_exist"))
         assert f.rexists()
 
-        test.write(["work", "i_exist_too"], "\n")
         f = fs.File(test.workpath("work", "i_exist_too"))
         assert f.rexists()
 
         RepositoryTestCase,
     ]
     for tclass in tclasses:
-        names = unittest.getTestCaseNames(tclass, 'test_')
+        names = unittest.getTestCaseNames(tclass, 'tttest_')
         suite.addTests(map(tclass, names))
     if not unittest.TextTestRunner().run(suite).wasSuccessful():
         sys.exit(1)

File test/symlink.py

 
 test.symlink('nonexistent', 'foo.h')
 
+expect = """\
+scons: *** Source `foo.h' not found, needed by target `%s'.  Stop.
+"""% foo_obj
+
 test.run(arguments = '.',
          status = 2,
-         stderr = None)
-
-expect = "scons: *** [%s] Error 1\n" % foo_obj
-test.fail_test(string.find(test.stderr(), expect) == -1)
+         stderr = expect)
 
 test.write('SConstruct', """
 Command('file.out', 'file.in', Copy('$TARGET', '$SOURCE'))