- 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,
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():
# 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
"""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)
"""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
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()
-