diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-19 15:43:36 +0000 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-20 17:29:13 +0000 |
commit | 9fa091fa51a2e6f0b1ed276756f457a862919847 (patch) | |
tree | f29a782209425de4cfbd03fe2e9c736c44613fd2 | |
parent | bfa8b4ca0fb51a2bae268fb78bc1550731152bb5 (diff) | |
download | buildstream-bschubert/mr938-comments.tar.gz |
utils.py: improve documentation of move_atomicbschubert/mr938-comments
-rw-r--r-- | buildstream/utils.py | 10 |
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) |