2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-22 18:07:12 +01:00

Issue 1487 - delete files or folders only if they exist on the filesystem

This commit is contained in:
Thomas Nagy 2014-09-21 10:10:55 +02:00
parent f990fca8ff
commit cb030505af
No known key found for this signature in database
GPG Key ID: 67A565EDFDF90E64

View File

@ -187,12 +187,13 @@ class Node(object):
os.chmod(self.abspath(), val)
def delete(self):
"""Delete the file/folders, and remove this node from the tree. It becomes invalid after that"""
"""Delete the file/folders if it exists, and remove this node from the tree. Do not use this object after calling this method."""
try:
if hasattr(self, 'children'):
shutil.rmtree(self.abspath())
else:
os.remove(self.abspath())
if os.path.exists(self.abspath()):
if hasattr(self, 'children'):
shutil.rmtree(self.abspath())
else:
os.remove(self.abspath())
finally:
self.evict()