File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -301,8 +301,16 @@ impl Storage {
301301 . parent ( )
302302 . ok_or_else ( || anyhow ! ( "index path without parent" ) ) ?,
303303 ) ?;
304- let mut file = fs:: File :: create ( & local_index_path) ?;
305- file. write_all ( & index_content) ?;
304+
305+ // when we don't have a locally cached index and many parallel request
306+ // we might download the same archive index multiple times here.
307+ // So we're storing the content into a temporary file before renaming it
308+ // into the final location.
309+ let mut tmpfile =
310+ tempfile:: NamedTempFile :: new_in ( & self . config . local_archive_cache_path ) ?;
311+ tmpfile. write_all ( & index_content) ?;
312+ let temp_path = tmpfile. into_temp_path ( ) ;
313+ fs:: rename ( temp_path, & local_index_path) ?;
306314 }
307315
308316 Ok ( local_index_path)
You can’t perform that action at this time.
0 commit comments