diff options
author | Ed Baunton <ebaunton1@bloomberg.net> | 2018-07-27 14:01:57 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-08-07 05:04:50 +0000 |
commit | 3d26ff6eff05648afdc3188175bd327c6f1676b1 (patch) | |
tree | de7476601a128b15051a9a6de2695bbb952fe46d /buildstream | |
parent | a8073264fb5e50090d64a8ad8acbb1ef64fda2f1 (diff) | |
download | buildstream-3d26ff6eff05648afdc3188175bd327c6f1676b1.tar.gz |
remote.py: Add support for marking downloaded files executable
Add an optional flag to make files executable after having downloaded them.
Instead of leaving the permissioning of downloaded file in remote.py up
to the user's umask; expressly set permissions to 0644 or 0755 if
executable.
Bump format version to 13.
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_versions.py | 2 | ||||
-rw-r--r-- | buildstream/plugins/sources/remote.py | 19 |
2 files changed, 18 insertions, 3 deletions
diff --git a/buildstream/_versions.py b/buildstream/_versions.py index 39ff30fc3..d774e5786 100644 --- a/buildstream/_versions.py +++ b/buildstream/_versions.py @@ -23,7 +23,7 @@ # This version is bumped whenever enhancements are made # to the `project.conf` format or the core element format. # -BST_FORMAT_VERSION = 12 +BST_FORMAT_VERSION = 13 # The base BuildStream artifact version diff --git a/buildstream/plugins/sources/remote.py b/buildstream/plugins/sources/remote.py index ad4cdab8b..a0809cb10 100644 --- a/buildstream/plugins/sources/remote.py +++ b/buildstream/plugins/sources/remote.py @@ -35,6 +35,10 @@ remote - stage files from remote urls # If not specified, the basename of the url will be used. # filename: customfilename + # Optionally specify whether the downloaded file should be + # marked executable. + # executable: true + # Specify the url. Using an alias defined in your project # configuration is encouraged. 'bst track' will update the # sha256sum in 'ref' to the downloaded file's sha256sum. @@ -43,6 +47,8 @@ remote - stage files from remote urls # Specify the ref. It's a sha256sum of the file you download. ref: 6c9f6f68a131ec6381da82f2bff978083ed7f4f7991d931bfa767b7965ebc94b + + .. note:: The ``remote`` plugin is available since :ref:`format version 10 <project_format_version>` @@ -60,22 +66,31 @@ class RemoteSource(DownloadableFileSource): super().configure(node) self.filename = self.node_get_member(node, str, 'filename', os.path.basename(self.url)) + self.executable = self.node_get_member(node, bool, 'executable', False) if os.sep in self.filename: raise SourceError('{}: filename parameter cannot contain directories'.format(self), reason="filename-contains-directory") - self.node_validate(node, DownloadableFileSource.COMMON_CONFIG_KEYS + ['filename']) + self.node_validate(node, DownloadableFileSource.COMMON_CONFIG_KEYS + ['filename', 'executable']) def get_unique_key(self): - return super().get_unique_key() + [self.filename] + return super().get_unique_key() + [self.filename, self.executable] def stage(self, directory): # Same as in local plugin, don't use hardlinks to stage sources, they # are not write protected in the sandbox. dest = os.path.join(directory, self.filename) with self.timed_activity("Staging remote file to {}".format(dest)): + utils.safe_copy(self._get_mirror_file(), dest) + # To prevent user's umask introducing variability here, explicitly set + # file modes. + if self.executable: + os.chmod(dest, 0o755) + else: + os.chmod(dest, 0o644) + def setup(): return RemoteSource |