Skip to content

Commit 6448b81

Browse files
committed
dist: drop another layer of abstraction
1 parent ed3de60 commit 6448b81

File tree

2 files changed

+31
-40
lines changed

2 files changed

+31
-40
lines changed

src/dist/component/package.rs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@ pub struct DirectoryPackage<P> {
3434
copy: bool,
3535
}
3636

37+
impl DirectoryPackage<temp::Dir> {
38+
pub(crate) fn compressed<R: Read>(
39+
stream: R,
40+
kind: CompressionKind,
41+
dl_cfg: &DownloadCfg<'_>,
42+
) -> Result<Self> {
43+
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)
47+
}
48+
CompressionKind::XZ => Self::from_tar(xz2::read::XzDecoder::new(stream), dl_cfg),
49+
}
50+
}
51+
52+
fn from_tar(stream: impl Read, dl_cfg: &DownloadCfg<'_>) -> Result<Self> {
53+
let temp_dir = dl_cfg.tmp_cx.new_directory()?;
54+
let mut archive = tar::Archive::new(stream);
55+
// The rust-installer packages unpack to a directory called
56+
// $pkgname-$version-$target. Skip that directory when
57+
// unpacking.
58+
unpack_without_first_dir(&mut archive, &temp_dir, dl_cfg)
59+
.context("failed to extract package")?;
60+
61+
Self::new(temp_dir, false)
62+
}
63+
}
64+
3765
impl<P: Deref<Target = Path>> DirectoryPackage<P> {
3866
pub fn new(path: P, copy: bool) -> Result<Self> {
3967
let file = utils::read_file("installer version", &path.join(VERSION_FILE))?;
@@ -116,43 +144,6 @@ impl<P: Deref<Target = Path>> DirectoryPackage<P> {
116144
}
117145
}
118146

119-
#[derive(Debug)]
120-
pub(crate) struct TarPackage(DirectoryPackage<temp::Dir>);
121-
122-
impl TarPackage {
123-
pub(crate) fn compressed<R: Read>(
124-
stream: R,
125-
kind: CompressionKind,
126-
dl_cfg: &DownloadCfg<'_>,
127-
) -> Result<Self> {
128-
match kind {
129-
CompressionKind::GZip => Self::new(flate2::read::GzDecoder::new(stream), dl_cfg),
130-
CompressionKind::ZStd => Self::new(zstd::stream::read::Decoder::new(stream)?, dl_cfg),
131-
CompressionKind::XZ => Self::new(xz2::read::XzDecoder::new(stream), dl_cfg),
132-
}
133-
}
134-
135-
fn new<R: Read>(stream: R, dl_cfg: &DownloadCfg<'_>) -> Result<Self> {
136-
let temp_dir = dl_cfg.tmp_cx.new_directory()?;
137-
let mut archive = tar::Archive::new(stream);
138-
// The rust-installer packages unpack to a directory called
139-
// $pkgname-$version-$target. Skip that directory when
140-
// unpacking.
141-
unpack_without_first_dir(&mut archive, &temp_dir, dl_cfg)
142-
.context("failed to extract package")?;
143-
144-
Ok(TarPackage(DirectoryPackage::new(temp_dir, false)?))
145-
}
146-
}
147-
148-
impl Deref for TarPackage {
149-
type Target = DirectoryPackage<temp::Dir>;
150-
151-
fn deref(&self) -> &Self::Target {
152-
&self.0
153-
}
154-
}
155-
156147
// Probably this should live in diskio but ¯\_(ツ)_/¯
157148
fn unpack_ram(
158149
io_chunk_size: usize,

src/dist/manifestation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tokio::sync::Semaphore;
1313
use tracing::{info, warn};
1414
use url::Url;
1515

16-
use crate::dist::component::{Components, TarPackage, Transaction};
16+
use crate::dist::component::{Components, DirectoryPackage, Transaction};
1717
use crate::dist::config::Config;
1818
use crate::dist::download::{DownloadCfg, DownloadStatus, File};
1919
use crate::dist::manifest::{Component, CompressionKind, HashedBinary, Manifest, TargetedPackage};
@@ -430,7 +430,7 @@ impl Manifestation {
430430

431431
// Install all the components in the installer
432432
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
433-
let package = TarPackage::compressed(reader, CompressionKind::GZip, dl_cfg)?;
433+
let package = DirectoryPackage::compressed(reader, CompressionKind::GZip, dl_cfg)?;
434434
for component in package.components() {
435435
tx = package.install(&self.installation, &component, None, tx)?;
436436
}
@@ -745,7 +745,7 @@ impl<'a> ComponentBinary<'a> {
745745
self.status.installing();
746746

747747
let reader = utils::FileReaderWithProgress::new_file(&installer_file)?;
748-
let package = TarPackage::compressed(reader, self.binary.compression, download_cfg)?;
748+
let package = DirectoryPackage::compressed(reader, self.binary.compression, download_cfg)?;
749749

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

0 commit comments

Comments
 (0)