[Notes] [Git][BuildStream/buildstream][bschubert/fix-atomic-move-git-repo] sources/pip.py: Use move_atomic instead of manual os.rename



Title: GitLab

Benjamin Schubert pushed to branch bschubert/fix-atomic-move-git-repo at BuildStream / buildstream

Commits:

1 changed file:

Changes:

  • buildstream/plugins/sources/pip.py
    ... ... @@ -68,7 +68,6 @@ details on common configuration options for sources.
    68 68
        The ``pip`` plugin is available since :ref:`format version 16 <project_format_version>`
    
    69 69
     """
    
    70 70
     
    
    71
    -import errno
    
    72 71
     import hashlib
    
    73 72
     import os
    
    74 73
     import re
    
    ... ... @@ -192,13 +191,14 @@ class PipSource(Source):
    192 191
                 # process has fetched the sources before us and ensure that we do
    
    193 192
                 # not raise an error in that case.
    
    194 193
                 try:
    
    195
    -                os.makedirs(self._mirror)
    
    196
    -                os.rename(package_dir, self._mirror)
    
    197
    -            except FileExistsError:
    
    198
    -                return
    
    194
    +                utils.move_atomic(package_dir, self._mirror)
    
    195
    +            except utils.DirectoryExistsError:
    
    196
    +                # Another process has beaten us and has fetched the sources
    
    197
    +                # before us.
    
    198
    +                pass
    
    199 199
                 except OSError as e:
    
    200
    -                if e.errno != errno.ENOTEMPTY:
    
    201
    -                    raise
    
    200
    +                raise SourceError("{}: Failed to move downloaded pip packages from '{}' to '{}': {}"
    
    201
    +                                  .format(self, package_dir, self._mirror, e)) from e
    
    202 202
     
    
    203 203
         def stage(self, directory):
    
    204 204
             with self.timed_activity("Staging Python packages", silent_nested=True):
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]