From b85dccca927bdd2e9c5d30841544ef4328ce9d56 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Tue, 1 Dec 2015 15:12:26 +0100 Subject: [PATCH] resources : added error handling for destination keyword on resource directive --- lib/spack/spack/directives.py | 20 +++++++++++++++++--- 1 file 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 @@ class OpenMpi(Package): * ``extends`` * ``patch`` * ``variant`` + * ``resource`` """ __all__ = ['depends_on', 'extends', 'provides', 'patch', 'version', @@ -49,9 +50,11 @@ class OpenMpi(Package): 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))