Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
Merge #466
Browse files Browse the repository at this point in the history
466: In-memory reading from tar archives instead of extract to temp folder r=koivunej a=Scondo

Get rid of work with filesystem in fs-unrelated tests.

No more problems like #465 lead to tests failure.

Co-authored-by: Scondo <[email protected]>
  • Loading branch information
bors[bot] and Scondo authored Aug 2, 2021
2 parents f403c35 + 5a8499e commit b63eb14
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions http/src/v0/root_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ mod tests {
use ipfs::{Block, Ipfs, IpfsTypes, Node};
use multihash::Sha2_256;
use std::convert::TryFrom;
use std::io::Read;
use std::path::PathBuf;

// Entry we'll use in expectations
Expand All @@ -279,15 +280,11 @@ mod tests {
let path = entry.path()?.into();
let size = header.size()?;

// writing to file is the only supported way to get the contents
let tempdir = tempfile::tempdir()?;
let temp_file = tempdir.path().join("temporary_file_for_testing.txt");
entry.unpack(&temp_file)?;

let bytes = std::fs::read(&temp_file);

// regardless of read success let's prefer deleting the file
std::fs::remove_file(&temp_file)?;
// From https://github.com/alexcrichton/tar-rs/blob/0.4.35/src/entry.rs#L281
// Preallocate some data but don't let ourselves get too crazy now.
let cap = std::cmp::min(entry.size(), 128 * 1024);
let mut v = Vec::with_capacity(cap as usize);
let bytes = entry.read_to_end(&mut v).map(|_| v);

// and only later check if the read succeeded
Entry::File(path, size, bytes?)
Expand Down

0 comments on commit b63eb14

Please sign in to comment.