diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-09 14:09:52 +0000 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-12 14:33:03 +0000 |
commit | 910169777dc8d68ce3545579068bed5c13ffceb2 (patch) | |
tree | ff58c7beb18a879c7aaad521db86e32155a01e44 | |
parent | f0c17aa7adcdad026f939f385ccf48afc41192bd (diff) | |
download | buildstream-bschubert/fix-atomic-move-git-repo.tar.gz |
sources/pip.py: Use move_atomic instead of manual os.renamebschubert/fix-atomic-move-git-repo
This uses move_atomic insteand of the manual os.rename and manual error
checking and throws a SourceError for consistency with other modules.
-rw-r--r-- | buildstream/plugins/sources/pip.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/buildstream/plugins/sources/pip.py b/buildstream/plugins/sources/pip.py index 2ef401620..511105abb 100644 --- a/buildstream/plugins/sources/pip.py +++ b/buildstream/plugins/sources/pip.py @@ -68,7 +68,6 @@ details on common configuration options for sources. The ``pip`` plugin is available since :ref:`format version 16 <project_format_version>` """ -import errno import hashlib import os import re @@ -192,13 +191,14 @@ class PipSource(Source): # process has fetched the sources before us and ensure that we do # not raise an error in that case. try: - os.makedirs(self._mirror) - os.rename(package_dir, self._mirror) - except FileExistsError: - return + utils.move_atomic(package_dir, self._mirror) + except utils.DirectoryExistsError: + # Another process has beaten us and has fetched the sources + # before us. + pass except OSError as e: - if e.errno != errno.ENOTEMPTY: - raise + raise SourceError("{}: Failed to move downloaded pip packages from '{}' to '{}': {}" + .format(self, package_dir, self._mirror, e)) from e def stage(self, directory): with self.timed_activity("Staging Python packages", silent_nested=True): |