From f01946052b159d26a59c759366f135eeaede8bd9 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Mon, 9 Sep 2002 03:31:10 +0000 Subject: [PATCH] Warn when -c can't remove a file. git-svn-id: http://scons.tigris.org/svn/scons/trunk@464 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 2 ++ src/engine/SCons/Node/FS.py | 7 +++++++ src/engine/SCons/Node/FSTests.py | 29 +++++++++++++++++++++++++++++ src/engine/SCons/Node/__init__.py | 4 ++++ src/engine/SCons/Script/__init__.py | 26 +++++++++----------------- test/option-c.py | 11 ++++++++++- 6 files changed, 61 insertions(+), 18 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index ea65a0a9..96e19397 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -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, diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index c4b220f2..7174b996 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -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(): diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index f87abe7f..adcccaed 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -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 diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index d12edaeb..09ceea07 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -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) diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index cff3a215..365a0b1e 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -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 diff --git a/test/option-c.py b/test/option-c.py index a686f5a7..6bb25daa 100644 --- a/test/option-c.py +++ b/test/option-c.py @@ -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() - -- 2.26.2