summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2018-11-09 14:04:46 +0000
committerBenjamin Schubert <ben.c.schubert@gmail.com>2018-11-12 14:33:03 +0000
commitf0c17aa7adcdad026f939f385ccf48afc41192bd (patch)
treefb1a3eaf8d336a0261b1e988e974c65037773b1b
parent6f3b0f95d65e6c682c9fccfd47adb2f110423e13 (diff)
downloadbuildstream-f0c17aa7adcdad026f939f385ccf48afc41192bd.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 b6e26ec8b..314971c17 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
@@ -108,17 +107,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 dest