summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2018-11-19 15:43:36 +0000
committerBenjamin Schubert <ben.c.schubert@gmail.com>2018-11-21 09:24:15 +0000
commitb2f604b8fa5535bca4d4567aba19ce5e118115a8 (patch)
tree088a1e54a414732b1c8a9af98d0648371224ee81
parenta50c598e8d223eb706c846363d09b3308dc6d916 (diff)
downloadbuildstream-b2f604b8fa5535bca4d4567aba19ce5e118115a8.tar.gz
utils.py: improve documentation of move_atomic
-rw-r--r--buildstream/utils.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/buildstream/utils.py b/buildstream/utils.py
index a0db963da..94c990357 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -512,10 +512,12 @@ def move_atomic(source, destination, *, ensure_parents=True):
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)