Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit ed3deb0

Browse files
committed
use tempfile to write last chunk
1 parent 8720d2e commit ed3deb0

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bottomless/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ arc-swap = "1.6"
2525
chrono = "0.4.23"
2626
uuid = "1.4.1"
2727
rand = "0.8.5"
28+
tempfile = "3.3.0"
2829

2930
[features]
3031
libsql_linked_statically = []

bottomless/src/read.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,18 @@ pub async fn upload_s3_multipart(
158158
//
159159
// This would only happen to databases that are around ~1 TiB.
160160
if !has_reached_eof {
161-
let mut last_chunk_path = std::env::temp_dir();
162-
last_chunk_path.push(rand::random::<u32>().to_string());
161+
let last_chunk_file = tempfile::NamedTempFile::new()?;
162+
let mut last_chunk_tokio_file =
163+
tokio::fs::File::from_std(last_chunk_file.as_file().try_clone()?);
163164

164-
let mut last_chunk_file = tokio::fs::File::create(&last_chunk_path).await?;
165-
tokio::io::copy(&mut reader, &mut last_chunk_file).await?;
165+
tokio::io::copy(&mut reader, &mut last_chunk_tokio_file).await?;
166166

167167
let part_out = client
168168
.upload_part()
169169
.bucket(bucket)
170170
.key(key)
171171
.upload_id(upload_id.clone())
172-
.body(ByteStream::from_path(&last_chunk_path).await?)
172+
.body(ByteStream::from_path(last_chunk_file.path()).await?)
173173
.part_number(LAST_PART)
174174
.send()
175175
.await?;
@@ -184,8 +184,6 @@ pub async fn upload_s3_multipart(
184184
)
185185
.build(),
186186
);
187-
188-
let _ = tokio::fs::remove_file(last_chunk_path).await;
189187
}
190188

191189
client

0 commit comments

Comments
 (0)