summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2018-11-21 09:52:42 +0000
committerBenjamin Schubert <ben.c.schubert@gmail.com>2018-11-21 09:52:42 +0000
commitdaca0c01c5dd56e99f89852a4c7643289396cfb2 (patch)
tree088a1e54a414732b1c8a9af98d0648371224ee81
parent7f316a768575289fec80fea8a6ea9e39fb47077f (diff)
parentb2f604b8fa5535bca4d4567aba19ce5e118115a8 (diff)
downloadbuildstream-daca0c01c5dd56e99f89852a4c7643289396cfb2.tar.gz
Merge branch 'bschubert/mr938-comments' into 'master'
Followup on MR 938, addressing additional comments See merge request BuildStream/buildstream!958
-rw-r--r--buildstream/utils.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/buildstream/utils.py b/buildstream/utils.py
index 968d87f7b..94c990357 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -505,17 +505,19 @@ def get_bst_version():
.format(__version__))
-def move_atomic(source, destination, ensure_parents=True):
+def move_atomic(source, destination, *, ensure_parents=True):
"""Move the source to the destination using atomic primitives.
This uses `os.rename` to move a file or directory to a new destination.
It wraps some `OSError` thrown errors to ensure their handling is correct.
The main reason for this to exist is that rename can throw different errors
- for the same symptom (https://www.unix.com/man-page/POSIX/3posix/rename/).
+ for the same symptom (https://www.unix.com/man-page/POSIX/3posix/rename/)
+ when we are moving a directory.
We are especially interested here in the case when the destination already
- exists. In this case, either EEXIST or ENOTEMPTY are thrown.
+ exists, is a directory and is not empty. In this case, either EEXIST or
+ ENOTEMPTY can be thrown.
In order to ensure consistent handling of these exceptions, this function
should be used instead of `os.rename`
@@ -525,6 +527,10 @@ def move_atomic(source, destination, ensure_parents=True):
destination (str or Path): destination to which to move the source
ensure_parents (bool): Whether or not to create the parent's directories
of the destination (default: True)
+ Raises:
+ DirectoryExistsError: if the destination directory already exists and is
+ not empty
+ OSError: if another filesystem level error occured
"""
if ensure_parents:
os.makedirs(os.path.dirname(str(destination)), exist_ok=True)