storage: fix _atomic_write to create hidden temporary files (#2010)

This commit is contained in:
Benjamin Dauvergne 2012-11-22 14:45:59 +01:00 committed by Thomas NOEL
parent 3b087fba26
commit b3a715a3b9
1 changed files with 3 additions and 1 deletions

View File

@ -51,7 +51,9 @@ def atomic_write(path, content, async=False):
'''Rewrite a complete file automatically, that is write to new file with '''Rewrite a complete file automatically, that is write to new file with
temporary name, fsync, then rename to final name. Use threads to remove blocking.''' temporary name, fsync, then rename to final name. Use threads to remove blocking.'''
def doit(): def doit():
fd, temp = tempfile.mkstemp(dir=os.path.dirname(path), prefix=os.path.basename(path)) dirname = os.path.dirname(path)
fd, temp = tempfile.mkstemp(dir=dirname,
prefix='.tmp-'+os.path.basename(path)+'-')
f = os.fdopen(fd, "w") f = os.fdopen(fd, "w")
if hasattr(content, 'read'): if hasattr(content, 'read'):
# file pointer # file pointer