diff options
author | Massimiliano Culpo <massimiliano.culpo@googlemail.com> | 2015-12-01 15:12:26 +0100 |
---|---|---|
committer | Massimiliano Culpo <massimiliano.culpo@googlemail.com> | 2015-12-01 15:12:26 +0100 |
commit | b85dccca927bdd2e9c5d30841544ef4328ce9d56 (patch) | |
tree | c593bbb5428c107a66c4e81e8ba5c4d836732bc2 /lib | |
parent | d3d9b5401b4d265f4de927cd34828a8c8b99e923 (diff) | |
download | spack-b85dccca927bdd2e9c5d30841544ef4328ce9d56.tar.gz spack-b85dccca927bdd2e9c5d30841544ef4328ce9d56.tar.bz2 spack-b85dccca927bdd2e9c5d30841544ef4328ce9d56.tar.xz spack-b85dccca927bdd2e9c5d30841544ef4328ce9d56.zip |
resources : added error handling for destination keyword on resource directive
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/directives.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py index 741df3a31b..48a7df7462 100644 --- a/lib/spack/spack/directives.py +++ b/lib/spack/spack/directives.py @@ -42,6 +42,7 @@ The available directives are: * ``extends`` * ``patch`` * ``variant`` + * ``resource`` """ __all__ = ['depends_on', 'extends', 'provides', 'patch', 'version', @@ -49,9 +50,11 @@ __all__ = ['depends_on', 'extends', 'provides', 'patch', 'version', import re import inspect +import os.path import functools from llnl.util.lang import * +from llnl.util.filesystem import join_path import spack import spack.spec @@ -271,16 +274,27 @@ def resource(pkg, **kwargs): List of recognized keywords: * 'when' : represents the condition upon which the resource is needed (optional) - * 'destination' : path where to extract / checkout the resource (optional) + * 'destination' : path where to extract / checkout the resource (optional). This path must be a relative path, + and it must fall inside the stage area of the main package. """ when = kwargs.get('when', pkg.name) - # FIXME : currently I assume destination to be a relative path (rooted at pkg.stage.source_path) destination = kwargs.get('destination', "") + # Check if the path is relative + if os.path.isabs(destination): + message = "The destination keyword of a resource directive can't be an absolute path.\n" + message += "\tdestination : '{dest}\n'".format(dest=destination) + raise RuntimeError(message) + # Check if the path falls within the main package stage area + test_path = 'stage_folder_root/' + normalized_destination = os.path.normpath(join_path(test_path, destination)) # Normalized absolute path + if test_path not in normalized_destination: + message = "The destination folder of a resource must fall within the main package stage directory.\n" + message += "\tdestination : '{dest}'\n".format(dest=destination) + raise RuntimeError(message) when_spec = parse_anonymous_spec(when, pkg.name) resources = pkg.resources.setdefault(when_spec, []) fetcher = from_kwargs(**kwargs) - # FIXME : should we infer the name somehow if not passed ? name = kwargs.get('name') resources.append(Resource(name, fetcher, destination)) |