Skip to content

Commit 0635282

Browse files
committed
dist: hoist creation of io_executor some more
1 parent e57c60b commit 0635282

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/dist/component/package.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ use anyhow::{Context, Result, anyhow, bail};
1212
use tar::EntryType;
1313
use tracing::warn;
1414

15-
use crate::diskio::{
16-
CompletedIo, Executor, FileBuffer, IO_CHUNK_SIZE, Item, Kind, get_executor, unpack_ram,
17-
};
15+
use crate::diskio::{CompletedIo, Executor, FileBuffer, IO_CHUNK_SIZE, Item, Kind};
1816
use crate::dist::component::components::{ComponentPart, ComponentPartKind, Components};
1917
use crate::dist::component::transaction::Transaction;
20-
use crate::dist::download::DownloadCfg;
2118
use crate::dist::manifest::CompressionKind;
2219
use crate::dist::temp;
2320
use crate::errors::RustupError;
@@ -38,33 +35,36 @@ impl DirectoryPackage<temp::Dir> {
3835
pub(crate) fn compressed<R: Read>(
3936
stream: R,
4037
kind: CompressionKind,
41-
dl_cfg: &DownloadCfg<'_>,
38+
temp_dir: temp::Dir,
39+
io_executor: Box<dyn Executor>,
4240
) -> Result<Self> {
4341
match kind {
44-
CompressionKind::GZip => Self::from_tar(flate2::read::GzDecoder::new(stream), dl_cfg),
45-
CompressionKind::ZStd => {
46-
Self::from_tar(zstd::stream::read::Decoder::new(stream)?, dl_cfg)
42+
CompressionKind::GZip => {
43+
Self::from_tar(flate2::read::GzDecoder::new(stream), temp_dir, io_executor)
44+
}
45+
CompressionKind::ZStd => Self::from_tar(
46+
zstd::stream::read::Decoder::new(stream)?,
47+
temp_dir,
48+
io_executor,
49+
),
50+
CompressionKind::XZ => {
51+
Self::from_tar(xz2::read::XzDecoder::new(stream), temp_dir, io_executor)
4752
}
48-
CompressionKind::XZ => Self::from_tar(xz2::read::XzDecoder::new(stream), dl_cfg),
4953
}
5054
}
5155

52-
fn from_tar(stream: impl Read, dl_cfg: &DownloadCfg<'_>) -> Result<Self> {
53-
let temp_dir = dl_cfg.tmp_cx.new_directory()?;
56+
fn from_tar(
57+
stream: impl Read,
58+
temp_dir: temp::Dir,
59+
io_executor: Box<dyn Executor>,
60+
) -> Result<Self> {
5461
let mut archive = tar::Archive::new(stream);
5562

5663
// The rust-installer packages unpack to a directory called
5764
// $pkgname-$version-$target. Skip that directory when
5865
// unpacking.
59-
unpack_without_first_dir(
60-
&mut archive,
61-
&temp_dir,
62-
get_executor(
63-
unpack_ram(IO_CHUNK_SIZE, dl_cfg.process.unpack_ram()?),
64-
dl_cfg.process.io_thread_count()?,
65-
),
66-
)
67-
.context("failed to extract package")?;
66+
unpack_without_first_dir(&mut archive, &temp_dir, io_executor)
67+
.context("failed to extract package")?;
6868

6969
Self::new(temp_dir, false)
7070
}

src/dist/manifestation.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use anyhow::{Context, Result, anyhow, bail};
1010
use futures_util::stream::{FuturesUnordered, StreamExt};
1111
use tracing::{info, warn};
1212

13+
use crate::diskio::{IO_CHUNK_SIZE, get_executor, unpack_ram};
1314
use crate::dist::component::{Components, DirectoryPackage, Transaction};
1415
use crate::dist::config::Config;
1516
use crate::dist::download::{DownloadCfg, DownloadStatus, File};
@@ -423,7 +424,13 @@ impl Manifestation {
423424

424425
// Install all the components in the installer
425426
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
426-
let package = DirectoryPackage::compressed(reader, CompressionKind::GZip, dl_cfg)?;
427+
let temp_dir = dl_cfg.tmp_cx.new_directory()?;
428+
let io_executor = get_executor(
429+
unpack_ram(IO_CHUNK_SIZE, dl_cfg.process.unpack_ram()?),
430+
dl_cfg.process.io_thread_count()?,
431+
);
432+
let package =
433+
DirectoryPackage::compressed(reader, CompressionKind::GZip, temp_dir, io_executor)?;
427434
for component in package.components() {
428435
tx = package.install(&self.installation, &component, None, tx)?;
429436
}
@@ -687,8 +694,13 @@ impl<'a> ComponentBinary<'a> {
687694
self.status.installing();
688695

689696
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
697+
let temp_dir = self.download_cfg.tmp_cx.new_directory()?;
698+
let io_executor = get_executor(
699+
unpack_ram(IO_CHUNK_SIZE, self.download_cfg.process.unpack_ram()?),
700+
self.download_cfg.process.io_thread_count()?,
701+
);
690702
let package =
691-
DirectoryPackage::compressed(reader, self.binary.compression, self.download_cfg)?;
703+
DirectoryPackage::compressed(reader, self.binary.compression, temp_dir, io_executor)?;
692704

693705
// If the package doesn't contain the component that the
694706
// manifest says it does then somebody must be playing a joke on us.

0 commit comments

Comments
 (0)