Skip to content

Commit

Permalink
Rewind inventory list files after download
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Nov 19, 2024
1 parent 0a5407e commit 55162a6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/s3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,15 @@ impl S3Client {
.rsplit_once('/')
.map_or(&*fspec.key, |(_, after)| after);
let url = self.inventory_base.with_key(&fspec.key);
let outfile = self.make_dl_tempfile(&PathBuf::from(format!("data/{fname}")), &url)?;
let mut outfile = self.make_dl_tempfile(&PathBuf::from(format!("data/{fname}")), &url)?;

Check warning on line 167 in src/s3/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/s3/mod.rs#L167

Added line #L167 was not covered by tests
self.download_object(&url, Some(&fspec.md5_checksum), &outfile)
.await?;
outfile
.rewind()
.map_err(|source| CsvDownloadError::Rewind {
url: url.clone(),
source,
})?;

Check warning on line 175 in src/s3/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/s3/mod.rs#L170-L175

Added lines #L170 - L175 were not covered by tests
Ok(InventoryList::from_gzip_csv_file(url, outfile))
}

Expand Down Expand Up @@ -304,6 +310,11 @@ pub(crate) enum CsvDownloadError {
Tempfile(#[from] TempfileError),
#[error(transparent)]
Download(#[from] DownloadError),
#[error("failed to rewind tempfile after downloading {url}")]
Rewind {
url: S3Location,
source: std::io::Error,
},
}

#[derive(Debug, Error)]
Expand Down

0 comments on commit 55162a6

Please sign in to comment.