try to fix fd issues
This commit is contained in:
parent
0fae7ac3b0
commit
0fedae9334
3 changed files with 40 additions and 17 deletions
|
@ -32,21 +32,22 @@ impl<'a> Uploader<'a> {
|
|||
// temp location for now
|
||||
let temp_path = Path::parse(Ulid::new().to_string())?;
|
||||
let mut s3_writer = BufWriter::new(s3.clone(), temp_path.clone());
|
||||
debug!("uploading to temp path: {}", temp_path);
|
||||
|
||||
// compress and upload nar
|
||||
let mut file_reader = nar.compress_and_hash().await?;
|
||||
let mut buf = BytesMut::with_capacity(CHUNK_SIZE);
|
||||
debug!("uploading to temp path: {}", temp_path);
|
||||
while let n = file_reader.read_buf(&mut buf).await?
|
||||
&& n != 0
|
||||
{
|
||||
s3_writer.write_all_buf(&mut buf).await?;
|
||||
loop {
|
||||
let mut buf = BytesMut::with_capacity(CHUNK_SIZE);
|
||||
let n = file_reader.read_buf(&mut buf).await?;
|
||||
s3_writer.put(buf.freeze()).await?;
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
drop(file_reader);
|
||||
|
||||
let mut nar_info = nar.get_narinfo()?;
|
||||
nar_info.add_signature(self.signing_key);
|
||||
trace!("narinfo: {:#}", nar_info);
|
||||
|
||||
// now that we can calculate the file_hash move the nar to where it should be
|
||||
let real_path = nar_url(
|
||||
|
@ -55,6 +56,8 @@ impl<'a> Uploader<'a> {
|
|||
.expect("file hash must be known at this point"),
|
||||
);
|
||||
debug!("moving {} to {}", temp_path, real_path);
|
||||
// the temp object must be done uploading
|
||||
s3_writer.shutdown().await?;
|
||||
// this is implemented as a copy-and-delete
|
||||
s3.rename(&temp_path, &real_path).await?;
|
||||
// set nar url in narinfo
|
||||
|
@ -63,6 +66,7 @@ impl<'a> Uploader<'a> {
|
|||
// upload narinfo
|
||||
let narinfo_path = self.path.narinfo_path();
|
||||
debug!("uploading narinfo: {}", narinfo_path);
|
||||
trace!("narinfo: {:#}", nar_info);
|
||||
s3.put(&narinfo_path, nar_info.to_string().into()).await?;
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue