mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-19 00:06:57 +00:00
fileutil: add move_into_place(), to perform the standard unix trick of atomically replacing a file, with a fallback for windows
This commit is contained in:
parent
b949ea4f32
commit
89f041ac83
@ -10,7 +10,7 @@
|
||||
Futz with files like a pro.
|
||||
"""
|
||||
|
||||
import exceptions, os, stat, tempfile, time
|
||||
import sys, exceptions, os, stat, tempfile, time
|
||||
|
||||
from twisted.python import log
|
||||
|
||||
@ -195,3 +195,10 @@ def du(basedir):
|
||||
size += os.path.getsize(fn)
|
||||
|
||||
return size
|
||||
|
||||
def move_into_place(source, dest):
|
||||
"""Atomically replace a file, or as near to it as the platform allows.
|
||||
The dest file may or may not exist."""
|
||||
if "win32" in sys.platform.lower():
|
||||
remove_if_possible(dest)
|
||||
os.rename(source, dest)
|
||||
|
Loading…
x
Reference in New Issue
Block a user