Skip to content

Commit 8be5d06

Browse files
committed
add rename to cache, avoid partial content
1 parent ffea7b2 commit 8be5d06

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

otsserver/backup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ def write_disk_cache(self, chunk, bytes):
139139
cache_path = self.cache_path + '/' + chunk_path
140140
os.makedirs(cache_path, exist_ok=True)
141141
cache_file = cache_path + '/' + chunk_str
142-
with open(cache_file, 'wb') as fd:
142+
cache_file_tmp = cache_file + '.tmp'
143+
with open(cache_file_tmp, 'wb') as fd:
143144
fd.write(bytes)
145+
os.rename(cache_file_tmp, cache_file) # rename is atomic
144146

145147
# The following is a shrinked version of the standard calendar http server, it only support the '/timestamp' endpoint
146148
# This way the backup server could serve request in place of the calendar serve which is backupping

0 commit comments

Comments
 (0)