summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2018-07-31 12:43:49 +0100
committerTiago Gomes <tiago.avv@gmail.com>2018-08-02 11:24:43 +0000
commit00f170b867a4adf4cc4d75af22a97d15b4435236 (patch)
treed227246575bc27865c23fdc57859a12f9883dd6e
parent33292be4618b83147258e729a44caa58859e4ba2 (diff)
downloadbuildstream-00f170b867a4adf4cc4d75af22a97d15b4435236.tar.gz
patch plugin: validate project paths
-rw-r--r--buildstream/plugins/sources/patch.py13
-rw-r--r--tests/sources/patch.py12
2 files changed, 11 insertions, 14 deletions
diff --git a/buildstream/plugins/sources/patch.py b/buildstream/plugins/sources/patch.py
index 11b66b3ea..2fa002080 100644
--- a/buildstream/plugins/sources/patch.py
+++ b/buildstream/plugins/sources/patch.py
@@ -1,5 +1,6 @@
#
# Copyright Bloomberg Finance LP
+# Copyright (C) 2018 Codethink Limited
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -16,6 +17,7 @@
#
# Authors:
# Chandan Singh <csingh43@bloomberg.net>
+# Tiago Gomes <tiago.gomes@codethink.co.uk>
"""
patch - apply locally stored patches
@@ -52,19 +54,12 @@ class PatchSource(Source):
# pylint: disable=attribute-defined-outside-init
def configure(self, node):
- self.path = self.node_get_member(node, str, "path")
+ self.path = self.node_get_project_path(node, 'path',
+ check_is_file=True)
self.strip_level = self.node_get_member(node, int, "strip-level", 1)
self.fullpath = os.path.join(self.get_project_directory(), self.path)
def preflight(self):
- # Check if the configured file really exists
- if not os.path.exists(self.fullpath):
- raise SourceError("Specified path '{}' does not exist".format(self.path),
- reason="patch-no-exist")
- elif not os.path.isfile(self.fullpath):
- raise SourceError("Specified path '{}' must be a file".format(self.path),
- reason="patch-not-a-file")
-
# Check if patch is installed, get the binary at the same time
self.host_patch = utils.get_host_tool("patch")
diff --git a/tests/sources/patch.py b/tests/sources/patch.py
index 697a0ccfb..17b650b02 100644
--- a/tests/sources/patch.py
+++ b/tests/sources/patch.py
@@ -1,7 +1,7 @@
import os
import pytest
-from buildstream._exceptions import ErrorDomain
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
from tests.testutils import cli
DATA_DIR = os.path.join(
@@ -15,13 +15,13 @@ def test_missing_patch(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
# Removing the local file causes preflight to fail
- localfile = os.path.join(datafiles.dirname, datafiles.basename, 'file_1.patch')
+ localfile = os.path.join(project, 'file_1.patch')
os.remove(localfile)
result = cli.run(project=project, args=[
'show', 'target.bst'
])
- result.assert_main_error(ErrorDomain.SOURCE, 'patch-no-exist')
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
@@ -29,13 +29,15 @@ def test_non_regular_file_patch(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
# Add a fifo, that's not a regular file, should cause explosions
- patch_path = os.path.join(datafiles.dirname, datafiles.basename, 'irregular_file.patch')
+ patch_path = os.path.join(datafiles.dirname, datafiles.basename,
+ 'irregular_file.patch')
os.mkfifo(patch_path)
result = cli.run(project=project, args=[
'show', 'irregular.bst'
])
- result.assert_main_error(ErrorDomain.SOURCE, "patch-not-a-file")
+ result.assert_main_error(ErrorDomain.LOAD,
+ LoadErrorReason.PROJ_PATH_INVALID_KIND)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))