diff options
Diffstat (limited to 'lib/spack/llnl/util/filesystem.py')
-rw-r--r-- | lib/spack/llnl/util/filesystem.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index b8d0b4d2f1..d6579555ad 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -41,6 +41,8 @@ __all__ = [ 'fix_darwin_install_name', 'force_remove', 'force_symlink', + 'chgrp', + 'chmod_x', 'copy', 'install', 'copy_tree', @@ -52,6 +54,7 @@ __all__ = [ 'partition_path', 'prefixes', 'remove_dead_links', + 'remove_directory_contents', 'remove_if_dead_link', 'remove_linked_tree', 'set_executable', @@ -1806,3 +1809,13 @@ def md5sum(file): with open(file, "rb") as f: md5.update(f.read()) return md5.digest() + + +def remove_directory_contents(dir): + """Remove all contents of a directory.""" + if os.path.exists(dir): + for entry in [os.path.join(dir, entry) for entry in os.listdir(dir)]: + if os.path.isfile(entry) or os.path.islink(entry): + os.unlink(entry) + else: + shutil.rmtree(entry) |