diff --git a/crates/node/src/mempool/txvalidation/download_manager.rs b/crates/node/src/mempool/txvalidation/download_manager.rs index 676505b8..f320ee17 100644 --- a/crates/node/src/mempool/txvalidation/download_manager.rs +++ b/crates/node/src/mempool/txvalidation/download_manager.rs @@ -95,8 +95,8 @@ pub async fn download_asset_file( // Create a tmp file during download. // This way the file won't be available for download from the other nodes // until it is completely written. - let mut tmp_file_path = file_path.clone(); - tmp_file_path.set_extension("tmp"); + let tmp_file_path = tmp_file_name(&file_path); + let fd = tokio::fs::File::create(&tmp_file_path).await?; let mut fd = tokio::io::BufWriter::new(fd); @@ -202,13 +202,13 @@ async fn server_process_file( ) -> std::result::Result>, hyper::Error> { let file_digest = &req.uri().path()[1..]; - let mut file_path = data_directory.join(file_digest); + let file_path = data_directory.join(file_digest); let file = match tokio::fs::File::open(&file_path).await { Ok(file) => file, Err(_) => { // Try to see if the file is currently being updated. - file_path.set_extension("tmp"); + let file_path = tmp_file_name(&file_path); let (status_code, message) = if file_path.as_path().exists() { ( StatusCode::PARTIAL_CONTENT, @@ -232,3 +232,12 @@ async fn server_process_file( .body(BodyExt::boxed(stream_body)) .unwrap()) } + +fn tmp_file_name(file_path: &Path) -> PathBuf { + let mut tmp_file_path = file_path.to_path_buf(); + match tmp_file_path.extension() { + Some(ext) => tmp_file_path.set_extension(format!("{}.{}", ext.to_string_lossy(), "tmp")), + None => tmp_file_path.set_extension("tmp"), + }; + tmp_file_path +}