@@ -1038,7 +1038,7 @@ def download_attachment_file(url, path, auth, as_app=False, fine=False):
10381038 bytes_downloaded += len (chunk )
10391039
10401040 # Atomic rename to final location
1041- os .rename (temp_path , path )
1041+ os .replace (temp_path , path )
10421042
10431043 metadata ["size_bytes" ] = bytes_downloaded
10441044 metadata ["success" ] = True
@@ -1459,7 +1459,7 @@ def download_attachments(
14591459
14601460 # Rename to add extension (already atomic from download)
14611461 try :
1462- os .rename (filepath , final_filepath )
1462+ os .replace (filepath , final_filepath )
14631463 metadata ["saved_as" ] = os .path .basename (final_filepath )
14641464 except Exception as e :
14651465 logger .warning (
@@ -1490,7 +1490,7 @@ def download_attachments(
14901490 manifest_path = os .path .join (attachments_dir , "manifest.json" )
14911491 with open (manifest_path + ".temp" , "w" ) as f :
14921492 json .dump (manifest , f , indent = 2 )
1493- os .rename (manifest_path + ".temp" , manifest_path ) # Atomic write
1493+ os .replace (manifest_path + ".temp" , manifest_path ) # Atomic write
14941494 logger .debug (
14951495 "Wrote manifest for {0} #{1}: {2} attachments" .format (
14961496 item_type_display , number , len (attachment_metadata_list )
@@ -1811,7 +1811,7 @@ def backup_issues(args, repo_cwd, repository, repos_template):
18111811
18121812 with codecs .open (issue_file + ".temp" , "w" , encoding = "utf-8" ) as f :
18131813 json_dump (issue , f )
1814- os .rename (issue_file + ".temp" , issue_file ) # Unlike json_dump, this is atomic
1814+ os .replace (issue_file + ".temp" , issue_file ) # Atomic write
18151815
18161816
18171817def backup_pulls (args , repo_cwd , repository , repos_template ):
@@ -1886,7 +1886,7 @@ def backup_pulls(args, repo_cwd, repository, repos_template):
18861886
18871887 with codecs .open (pull_file + ".temp" , "w" , encoding = "utf-8" ) as f :
18881888 json_dump (pull , f )
1889- os .rename (pull_file + ".temp" , pull_file ) # Unlike json_dump, this is atomic
1889+ os .replace (pull_file + ".temp" , pull_file ) # Atomic write
18901890
18911891
18921892def backup_milestones (args , repo_cwd , repository , repos_template ):
@@ -2203,5 +2203,5 @@ def json_dump_if_changed(data, output_file_path):
22032203 temp_file = output_file_path + ".temp"
22042204 with codecs .open (temp_file , "w" , encoding = "utf-8" ) as f :
22052205 f .write (new_content )
2206- os .rename (temp_file , output_file_path ) # Atomic on POSIX systems
2206+ os .replace (temp_file , output_file_path ) # Atomic write
22072207 return True
0 commit comments