... |
... |
@@ -502,7 +502,7 @@ def get_bst_version(): |
502
|
502
|
|
503
|
503
|
@contextmanager
|
504
|
504
|
def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None,
|
505
|
|
- errors=None, newline=None, closefd=True, opener=None):
|
|
505
|
+ errors=None, newline=None, closefd=True, opener=None, tempdir=None):
|
506
|
506
|
"""Save a file with a temporary name and rename it into place when ready.
|
507
|
507
|
|
508
|
508
|
This is a context manager which is meant for saving data to files.
|
... |
... |
@@ -529,8 +529,9 @@ def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None, |
529
|
529
|
# https://bugs.python.org/issue8604
|
530
|
530
|
|
531
|
531
|
assert os.path.isabs(filename), "The utils.save_file_atomic() parameter ``filename`` must be an absolute path"
|
532
|
|
- dirname = os.path.dirname(filename)
|
533
|
|
- fd, tempname = tempfile.mkstemp(dir=dirname)
|
|
532
|
+ if tempdir is None:
|
|
533
|
+ tempdir = os.path.dirname(filename)
|
|
534
|
+ fd, tempname = tempfile.mkstemp(dir=tempdir)
|
534
|
535
|
os.close(fd)
|
535
|
536
|
|
536
|
537
|
f = open(tempname, mode=mode, buffering=buffering, encoding=encoding,
|
... |
... |
@@ -562,6 +563,9 @@ def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None, |
562
|
563
|
#
|
563
|
564
|
# Get the disk usage of a given directory in bytes.
|
564
|
565
|
#
|
|
566
|
+# This function assumes that files do not inadvertantly
|
|
567
|
+# disappear while this function is running.
|
|
568
|
+#
|
565
|
569
|
# Arguments:
|
566
|
570
|
# (str) The path whose size to check.
|
567
|
571
|
#
|