... |
... |
@@ -505,17 +505,19 @@ def get_bst_version(): |
505
|
505
|
.format(__version__))
|
506
|
506
|
|
507
|
507
|
|
508
|
|
-def move_atomic(source, destination, ensure_parents=True):
|
|
508
|
+def move_atomic(source, destination, *, ensure_parents=True):
|
509
|
509
|
"""Move the source to the destination using atomic primitives.
|
510
|
510
|
|
511
|
511
|
This uses `os.rename` to move a file or directory to a new destination.
|
512
|
512
|
It wraps some `OSError` thrown errors to ensure their handling is correct.
|
513
|
513
|
|
514
|
514
|
The main reason for this to exist is that rename can throw different errors
|
515
|
|
- for the same symptom (https://www.unix.com/man-page/POSIX/3posix/rename/).
|
|
515
|
+ for the same symptom (https://www.unix.com/man-page/POSIX/3posix/rename/)
|
|
516
|
+ when we are moving a directory.
|
516
|
517
|
|
517
|
518
|
We are especially interested here in the case when the destination already
|
518
|
|
- exists. In this case, either EEXIST or ENOTEMPTY are thrown.
|
|
519
|
+ exists, is a directory and is not empty. In this case, either EEXIST or
|
|
520
|
+ ENOTEMPTY can be thrown.
|
519
|
521
|
|
520
|
522
|
In order to ensure consistent handling of these exceptions, this function
|
521
|
523
|
should be used instead of `os.rename`
|
... |
... |
@@ -525,6 +527,10 @@ def move_atomic(source, destination, ensure_parents=True): |
525
|
527
|
destination (str or Path): destination to which to move the source
|
526
|
528
|
ensure_parents (bool): Whether or not to create the parent's directories
|
527
|
529
|
of the destination (default: True)
|
|
530
|
+ Raises:
|
|
531
|
+ DirectoryExistsError: if the destination directory already exists and is
|
|
532
|
+ not empty
|
|
533
|
+ OSError: if another filesystem level error occured
|
528
|
534
|
"""
|
529
|
535
|
if ensure_parents:
|
530
|
536
|
os.makedirs(os.path.dirname(str(destination)), exist_ok=True)
|