Warn when -c can't remove a file.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 9 Sep 2002 03:31:10 +0000 (03:31 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 9 Sep 2002 03:31:10 +0000 (03:31 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@464 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py
src/engine/SCons/Node/__init__.py
src/engine/SCons/Script/__init__.py
test/option-c.py

index ea65a0a9b174090f9790202d9c2ad40221c92cc1..96e1939761f981912df788a2d2406eb4def5f408 100644 (file)
@@ -35,6 +35,8 @@ RELEASE 0.09 -
   - Fix an exception thrown when a Default() directory was specified
     when using the -U option.
 
+  - Issue a warning when -c can't remove a target.
+
  From Anthony Roach:
 
  - Fixed use of command lines with spaces in their arguments,
index c4b220f210153d547dd10379ce78daac0c163006..7174b9961147834fbd5b982b8d01fba9142504b7 100644 (file)
@@ -781,6 +781,13 @@ class File(Entry):
         else:
             self.__createDir()
 
+    def remove(self):
+        """Remove this file."""
+        if os.path.exists(self.path):
+            os.unlink(self.path)
+            return 1
+        return None
+
     def current(self, calc):
         bsig = calc.bsig(self)
         if not self.exists():
index f87abe7f91601a5f8330b50b10a891632b854c14..adcccaed0399178f0dfcda745fd070e320224fbe 100644 (file)
@@ -583,6 +583,35 @@ class FSTestCase(unittest.TestCase):
 
         # XXX test current()
 
+        d = fs.Dir('dir')
+        r = d.remove()
+        assert r is None, r
+
+        f = fs.File('does_not_exist')
+        r = f.remove()
+        assert r == None, r
+
+        test.write('exists', "exists\n")
+        f = fs.File('exists')
+        r = f.remove()
+        assert r, r
+
+        test.write('can_not_remove', "can_not_remove\n")
+        test.writable(test.workpath('.'), 0)
+        fp = open(test.workpath('can_not_remove'))
+
+        f = fs.File('can_not_remove')
+        exc_caught = 0 
+        try:
+            r = f.remove()
+        except OSError:
+            exc_caught = 1
+
+        fp.close()
+
+        assert exc_caught, "Should have caught an OSError, r = " + str(r)
+
+
 class RepositoryTestCase(unittest.TestCase):
     def runTest(self):
         """Test FS (file system) Repository operations
index d12edaeb952f095c135b518ec497b650fe7b456b..09ceea07f46c328d6efcc5d30febdbc49510c647 100644 (file)
@@ -339,6 +339,10 @@ class Node:
         """Prepare for this Node to be created:  no-op by default."""
         pass
 
+    def remove(self):
+        """Remove this Node:  no-op by default."""
+        return None
+
     def add_dependency(self, depend):
         """Adds dependencies. The depend argument must be a list."""
         self._add_child(self.depends, depend)
index cff3a215bdbc4295664a5c5b1d7e050f7690c2c9..365a0b1e72b590fa419c9494f893a2700a6720d8 100644 (file)
@@ -130,26 +130,18 @@ class CleanTask(SCons.Taskmaster.Task):
     """An SCons clean task."""
     def show(self):
         if self.targets[0].builder or self.targets[0].side_effect:
-            print "Removed " + self.targets[0].path
+            print "Removed " + str(self.targets[0])
 
     def remove(self):
         if self.targets[0].builder or self.targets[0].side_effect:
-            try:
-                os.unlink(self.targets[0].path)
-            except OSError:
-                pass
-            else:
-                print "Removed " + self.targets[0].path
-            try:
-                for t in self.targets[1:]:
-                    try:
-                        os.unlink(t.path)
-                    except OSError:
-                        pass
-                    else:
-                        print "Removed " + t.path
-            except IndexError:
-                pass
+            for t in self.targets:
+                try:
+                    removed = t.remove()
+                except OSError, e:
+                    print "scons: Could not remove '%s':" % str(t), e.strerror
+                else:
+                    if removed:
+                        print "Removed " + str(t)
 
     execute = remove
 
index a686f5a794fe37898ad6039bdec0cc462429d656..6bb25daa159f4f4a0339ee46e097b0b48142bdd0 100644 (file)
@@ -121,5 +121,14 @@ test.fail_test(test.read(test.workpath('foo2.xxx')) != "foo2.in\n")
 test.fail_test(test.read(test.workpath('foo2.out')) != "foo2.in\n")
 test.fail_test(test.read(test.workpath('foo3.out')) != "foo3.in\n")
 
+test.writable('.', 0)
+f = open(test.workpath('foo1.out'))
+
+test.run(arguments = '-c foo1.out',
+         stdout = "scons: Could not remove 'foo1.out': Permission denied\n")
+
+test.fail_test(not os.path.exists(test.workpath('foo1.out')))
+
+f.close()
+
 test.pass_test()