summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2016-06-29 01:41:55 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2016-06-29 01:41:55 -0700
commitc99663211379389f416c5ba50a759555e2b1f9ec (patch)
tree7f104404cddd8e310c19643cde5878a56ec4b52c
parentbc1320d83a7822bf0c7cf738d34d986690691ae4 (diff)
downloadspack-c99663211379389f416c5ba50a759555e2b1f9ec.tar.gz
spack-c99663211379389f416c5ba50a759555e2b1f9ec.tar.bz2
spack-c99663211379389f416c5ba50a759555e2b1f9ec.tar.xz
spack-c99663211379389f416c5ba50a759555e2b1f9ec.zip
Add spack purge --cache to purge local archive cache.
-rw-r--r--.gitignore1
-rw-r--r--lib/spack/spack/cmd/purge.py26
-rw-r--r--lib/spack/spack/fetch_strategy.py7
3 files changed, 30 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 643e5d9b03..040df3eafd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
/var/spack/stage
+/var/spack/cache
*.pyc
/opt/
*~
diff --git a/lib/spack/spack/cmd/purge.py b/lib/spack/spack/cmd/purge.py
index 7b33ef7f69..f4e27a3969 100644
--- a/lib/spack/spack/cmd/purge.py
+++ b/lib/spack/spack/cmd/purge.py
@@ -22,9 +22,31 @@
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
+import spack
import spack.stage as stage
-description = "Remove all temporary build files and downloaded archives"
+description = "Remove temporary build files and/or downloaded archives"
+
+
+def setup_parser(subparser):
+ subparser.add_argument(
+ '-s', '--stage', action='store_true', default=True,
+ help="Remove all temporary build stages (default).")
+ subparser.add_argument(
+ '-c', '--cache', action='store_true', help="Remove cached downloads.")
+ subparser.add_argument(
+ '-a', '--all', action='store_true',
+ help="Remove all of the above.")
+
def purge(parser, args):
- stage.purge()
+ # Special case: no flags.
+ if not any((args.stage, args.cache, args.all)):
+ stage.purge()
+ return
+
+ # handle other flags with fall through.
+ if args.stage or args.all:
+ stage.purge()
+ if args.cache or args.all:
+ spack.cache.destroy()
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index 6f28ec34b2..69c04f7920 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -361,7 +361,7 @@ class CacheURLFetchStrategy(URLFetchStrategy):
"""The resource associated with a cache URL may be out of date."""
def __init__(self, *args, **kwargs):
super(CacheURLFetchStrategy, self).__init__(*args, **kwargs)
-
+
@_needs_stage
def fetch(self):
super(CacheURLFetchStrategy, self).fetch()
@@ -853,11 +853,14 @@ class FsCache(object):
dst = join_path(self.root, relativeDst)
mkdirp(os.path.dirname(dst))
fetcher.archive(dst)
-
+
def fetcher(self, targetPath, digest):
url = "file://" + join_path(self.root, targetPath)
return CacheURLFetchStrategy(url, digest)
+ def destroy(self):
+ shutil.rmtree(self.root, ignore_errors=True)
+
class FetchError(spack.error.SpackError):