Don't create a directory Node when a file already exists there, and vice versa. ...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 25 Apr 2002 10:28:24 +0000 (10:28 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 25 Apr 2002 10:28:24 +0000 (10:28 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@349 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py

index 67a05744ba6c4af9c94835916bac87fe07d824d7..3bb532dd3cdef9102d930f4b3da48459e43ba5f4 100644 (file)
@@ -14,6 +14,9 @@ RELEASE 0.07 -
 
   - Changes to build SCons packages on IRIX (and other *NIces).
 
+  - Don't create a directory Node when a file already exists there,
+    and vice versa.
+
   From Charles Crain:
 
   - Internal cleanup of environment passing to function Actions.
index 861fbaf7983d4e513c8ff823cc39ca0a629a9e81..d629d4066778eef048d1b052546f5f5092bb9b9b 100644 (file)
@@ -167,6 +167,7 @@ class FS:
             path_comp = path_comp[1:]
         else:
             path_comp = [ path_first, ] + path_comp[1:]
+            
         # Lookup the directory
         for path_name in path_comp[:-1]:
             path_norm = _my_normcase(path_name)
@@ -176,6 +177,14 @@ class FS:
             except KeyError:
                 if not create:
                     raise UserError
+
+                # look at the actual filesystem and make sure there isn't
+                # a file already there
+                path = os.path.join(str(directory), path_name)
+                if os.path.isfile(path):
+                    raise TypeError, \
+                          "File %s found where directory expected." % path
+
                 dir_temp = Dir(path_name, directory)
                 directory.entries[path_norm] = dir_temp
                 directory.add_wkid(dir_temp)
@@ -186,6 +195,19 @@ class FS:
         except KeyError:
             if not create:
                 raise UserError
+
+            # make sure we don't create File nodes when there is actually
+            # a directory at that path on the disk, and vice versa
+            path = os.path.join(str(directory), path_comp[-1])
+            if fsclass == File:
+                if os.path.isdir(path):
+                    raise TypeError, \
+                          "Directory %s found where file expected." % path
+            elif fsclass == Dir:
+                if os.path.isfile(path):
+                    raise TypeError, \
+                          "File %s found where directory expected." % path
+            
             ret = fsclass(path_comp[-1], directory)
             directory.entries[file_name] = ret
             directory.add_wkid(ret)
index 0259debf751e0e69184470779bc35956053b4e7b..4cf3cb51030d183bb512a08c9d75ebef8b017d8a 100644 (file)
@@ -487,6 +487,21 @@ class FSTestCase(unittest.TestCase):
         parents = f1.get_parents()
         assert parents == [ d1 ], parents
 
+        test.write("i_am_not_a_directory", "\n")
+        exc_caught = 0        
+        try:
+            fs.Dir(test.workpath("i_am_not_a_directory"))
+        except TypeError:
+            exc_caught = 1
+        assert exc_caught, "Should have caught a TypeError"
+        test.unlink("i_am_not_a_directory")
+
+        exc_caught = 0
+        try:
+            fs.File(sub_dir)
+        except TypeError:
+            exc_caught = 1
+        assert exc_caught, "Should have caught a TypeError"
 
 class find_fileTestCase(unittest.TestCase):
     def runTest(self):