Commit 2cb143e8 authored by Benjamin Schubert's avatar Benjamin Schubert
Browse files

cascache.py: use move_atomic instead of manual error checking

parent b68f02c5
Loading
Loading
Loading
Loading
+5 −9
Original line number Diff line number Diff line
@@ -108,16 +108,12 @@ class CASCache():
            checkoutdir = os.path.join(tmpdir, ref)
            self._checkout(checkoutdir, tree)

            os.makedirs(os.path.dirname(dest), exist_ok=True)
            try:
                os.rename(checkoutdir, dest)
                utils.move_atomic(checkoutdir, dest)
            except DirectoryExistsError:
                # Another process beat us to renamse
                pass
            except OSError as e:
                # With rename it's possible to get either ENOTEMPTY or EEXIST
                # in the case that the destination path is a not empty directory.
                #
                # If rename fails with these errors, another process beat
                # us to it so just ignore.
                if e.errno not in [errno.ENOTEMPTY, errno.EEXIST]:
                raise CASError("Failed to extract directory for ref '{}': {}".format(ref, e)) from e

        return dest