diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-09 14:09:52 +0000 |
---|---|---|
committer | richardmaw-codethink <richard.maw@codethink.co.uk> | 2018-11-19 11:39:51 +0000 |
commit | d32e0b83cdf0741834fef5e9b74d8c7cdabd1965 (patch) | |
tree | d52434970f7377c8b83aad2de133e3ba496f34b7 | |
parent | fd9e46be02a2e74b6caa09db423bac1586689c39 (diff) | |
download | buildstream-d32e0b83cdf0741834fef5e9b74d8c7cdabd1965.tar.gz |
sources/pip.py: Use move_atomic instead of manual os.rename
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 df2eeb5db..abef1fd0d 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 @@ -193,13 +192,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): |