[Notes] [Git][BuildStream/buildstream][bschubert/fix-atomic-move-git-repo] 2 commits: cascache.py: use move_atomic instead of manual error checking



Title: GitLab

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

Commits:

2 changed files:

Changes:

  • buildstream/_artifactcache/cascache.py
    ... ... @@ -108,17 +108,13 @@ class CASCache():
    108 108
                 checkoutdir = os.path.join(tmpdir, ref)
    
    109 109
                 self._checkout(checkoutdir, tree)
    
    110 110
     
    
    111
    -            os.makedirs(os.path.dirname(dest), exist_ok=True)
    
    112 111
                 try:
    
    113
    -                os.rename(checkoutdir, dest)
    
    112
    +                utils.move_atomic(checkoutdir, dest)
    
    113
    +            except DirectoryExistsError:
    
    114
    +                # Another process beat us to rename
    
    115
    +                pass
    
    114 116
                 except OSError as e:
    
    115
    -                # With rename it's possible to get either ENOTEMPTY or EEXIST
    
    116
    -                # in the case that the destination path is a not empty directory.
    
    117
    -                #
    
    118
    -                # If rename fails with these errors, another process beat
    
    119
    -                # us to it so just ignore.
    
    120
    -                if e.errno not in [errno.ENOTEMPTY, errno.EEXIST]:
    
    121
    -                    raise CASError("Failed to extract directory for ref '{}': {}".format(ref, e)) from e
    
    117
    +                raise CASError("Failed to extract directory for ref '{}': {}".format(ref, e)) from e
    
    122 118
     
    
    123 119
             return dest
    
    124 120
     
    

  • buildstream/plugins/sources/pip.py
    ... ... @@ -192,13 +192,14 @@ class PipSource(Source):
    192 192
                 # process has fetched the sources before us and ensure that we do
    
    193 193
                 # not raise an error in that case.
    
    194 194
                 try:
    
    195
    -                os.makedirs(self._mirror)
    
    196
    -                os.rename(package_dir, self._mirror)
    
    197
    -            except FileExistsError:
    
    198
    -                return
    
    195
    +                utils.move_atomic(package_dir, self._mirror)
    
    196
    +            except DirectoryExistsError:
    
    197
    +                # Another process has beaten us and has fetched the sources
    
    198
    +                # before us.
    
    199
    +                pass
    
    199 200
                 except OSError as e:
    
    200
    -                if e.errno != errno.ENOTEMPTY:
    
    201
    -                    raise
    
    201
    +                raise SourceError("{}: Failed to move downloaded pip packages from '{}' to '{}': {}"
    
    202
    +                                  .format(self.source, package_dir, self._mirror, e)) from e
    
    202 203
     
    
    203 204
         def stage(self, directory):
    
    204 205
             with self.timed_activity("Staging Python packages", silent_nested=True):
    



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