mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 05:28:04 +00:00
stop writing .backup files for normal overwrites
This commit is contained in:
parent
e000047932
commit
47b1787633
@ -990,7 +990,6 @@ class WriteFileMixin(object):
|
||||
|
||||
precondition_abspath(abspath_u)
|
||||
replacement_path_u = abspath_u + u".tmp" # FIXME more unique
|
||||
backup_path_u = abspath_u + u".backup"
|
||||
if now is None:
|
||||
now = time.time()
|
||||
|
||||
@ -1011,18 +1010,7 @@ class WriteFileMixin(object):
|
||||
return self._rename_conflicted_file(abspath_u, replacement_path_u)
|
||||
else:
|
||||
try:
|
||||
# XXX this is wrong; I think we're right now *always*
|
||||
# creating a .backup file if we a) downloaded
|
||||
# something and b) we already had a file.
|
||||
# so if you have alice + bob and file0:
|
||||
# - alice adds file0
|
||||
# - bob downloads file0
|
||||
# - alice changes file0
|
||||
# - bob downloads file0 (and creates file0.backup)
|
||||
# - alice changes file0
|
||||
# - bob downloads file0 (tries to create file0.backup, then makes file0.conflict)
|
||||
|
||||
fileutil.replace_file(abspath_u, replacement_path_u, backup_path_u)
|
||||
fileutil.replace_file(abspath_u, replacement_path_u)
|
||||
return abspath_u
|
||||
except fileutil.ConflictError:
|
||||
return self._rename_conflicted_file(abspath_u, replacement_path_u)
|
||||
|
@ -613,12 +613,13 @@ if sys.platform == "win32":
|
||||
def rename_no_overwrite(source_path, dest_path):
|
||||
os.rename(source_path, dest_path)
|
||||
|
||||
def replace_file(replaced_path, replacement_path, backup_path):
|
||||
def replace_file(replaced_path, replacement_path):
|
||||
precondition_abspath(replaced_path)
|
||||
precondition_abspath(replacement_path)
|
||||
precondition_abspath(backup_path)
|
||||
|
||||
r = ReplaceFileW(replaced_path, replacement_path, backup_path,
|
||||
# no "backup" path (the first None) because we don't want to
|
||||
# create a backup file
|
||||
r = ReplaceFileW(replaced_path, replacement_path, None,
|
||||
REPLACEFILE_IGNORE_MERGE_ERRORS, None, None)
|
||||
if r == 0:
|
||||
# The UnableToUnlinkReplacementError case does not happen on Windows;
|
||||
@ -640,19 +641,13 @@ else:
|
||||
except EnvironmentError:
|
||||
reraise(UnableToUnlinkReplacementError)
|
||||
|
||||
def replace_file(replaced_path, replacement_path, backup_path):
|
||||
def replace_file(replaced_path, replacement_path):
|
||||
precondition_abspath(replaced_path)
|
||||
precondition_abspath(replacement_path)
|
||||
precondition_abspath(backup_path)
|
||||
|
||||
if not os.path.exists(replacement_path):
|
||||
raise ConflictError("Replacement file not found: %r" % (replacement_path,))
|
||||
|
||||
try:
|
||||
os.rename(replaced_path, backup_path)
|
||||
except OSError as e:
|
||||
if e.errno != ENOENT:
|
||||
raise
|
||||
try:
|
||||
rename_no_overwrite(replacement_path, replaced_path)
|
||||
except EnvironmentError:
|
||||
|
Loading…
Reference in New Issue
Block a user