summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2018-11-09 14:04:46 +0000
committerrichardmaw-codethink <richard.maw@codethink.co.uk>2018-11-19 11:39:51 +0000
commitfd9e46be02a2e74b6caa09db423bac1586689c39 (patch)
treefe5eb0d5c8d6d188f204af6f54f8dbbbafdc19fe
parent88089d2d3451573b109bd396aa4df033192375ce (diff)
downloadbuildstream-fd9e46be02a2e74b6caa09db423bac1586689c39.tar.gz
cascache.py: use move_atomic instead of manual error checking
-rw-r--r--buildstream/_artifactcache/cascache.py15
1 files changed, 5 insertions, 10 deletions
diff --git a/buildstream/_artifactcache/cascache.py b/buildstream/_artifactcache/cascache.py
index f07bd24a1..04c26edfa 100644
--- a/buildstream/_artifactcache/cascache.py
+++ b/buildstream/_artifactcache/cascache.py
@@ -24,7 +24,6 @@ import os
import stat
import tempfile
import uuid
-import errno
from urllib.parse import urlparse
import grpc
@@ -140,17 +139,13 @@ 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 utils.DirectoryExistsError:
+ # Another process beat us to rename
+ 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
+ raise CASError("Failed to extract directory for ref '{}': {}".format(ref, e)) from e
return originaldest