... |
... |
@@ -496,7 +496,7 @@ def get_bst_version(): |
496
|
496
|
|
497
|
497
|
@contextmanager
|
498
|
498
|
def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None,
|
499
|
|
- errors=None, newline=None, closefd=True, opener=None):
|
|
499
|
+ errors=None, newline=None, closefd=True, opener=None, tempdir=None):
|
500
|
500
|
"""Save a file with a temporary name and rename it into place when ready.
|
501
|
501
|
|
502
|
502
|
This is a context manager which is meant for saving data to files.
|
... |
... |
@@ -523,8 +523,9 @@ def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None, |
523
|
523
|
# https://bugs.python.org/issue8604
|
524
|
524
|
|
525
|
525
|
assert os.path.isabs(filename), "The utils.save_file_atomic() parameter ``filename`` must be an absolute path"
|
526
|
|
- dirname = os.path.dirname(filename)
|
527
|
|
- fd, tempname = tempfile.mkstemp(dir=dirname)
|
|
526
|
+ if tempdir is None:
|
|
527
|
+ tempdir = os.path.dirname(filename)
|
|
528
|
+ fd, tempname = tempfile.mkstemp(dir=tempdir)
|
528
|
529
|
os.close(fd)
|
529
|
530
|
|
530
|
531
|
f = open(tempname, mode=mode, buffering=buffering, encoding=encoding,
|
... |
... |
@@ -556,6 +557,9 @@ def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None, |
556
|
557
|
#
|
557
|
558
|
# Get the disk usage of a given directory in bytes.
|
558
|
559
|
#
|
|
560
|
+# This function assumes that files do not inadvertantly
|
|
561
|
+# disappear while this function is running.
|
|
562
|
+#
|
559
|
563
|
# Arguments:
|
560
|
564
|
# (str) The path whose size to check.
|
561
|
565
|
#
|