Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zstd support #2676

Merged
merged 4 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ toml = "0.5"
url = "2.1"
wait-timeout = "0.2"
xz2 = "0.1.3"
zstd = "0.6"

[dependencies.retry]
default-features = false
Expand Down
36 changes: 36 additions & 0 deletions src/dist/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,39 @@ impl<'a> Package for TarXzPackage<'a> {
self.0.components()
}
}

#[derive(Debug)]
pub struct TarZStdPackage<'a>(TarPackage<'a>);

impl<'a> TarZStdPackage<'a> {
pub fn new<R: Read>(
stream: R,
temp_cfg: &'a temp::Cfg,
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
) -> Result<Self> {
let stream = zstd::stream::read::Decoder::new(stream)?;
Ok(TarZStdPackage(TarPackage::new(
stream,
temp_cfg,
notify_handler,
)?))
}
}

impl<'a> Package for TarZStdPackage<'a> {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
fn install<'b>(
&self,
target: &Components,
component: &str,
short_name: Option<&str>,
tx: Transaction<'b>,
) -> Result<Transaction<'b>> {
self.0.install(target, component, short_name, tx)
}
fn components(&self) -> Vec<String> {
self.0.components()
}
}
9 changes: 7 additions & 2 deletions src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,23 @@ pub struct TargetedPackage {
pub enum CompressionKind {
GZip,
XZ,
ZStd,
}

/// Each compression kind, in order of preference for use, from most desirable
/// to least desirable.
static COMPRESSION_KIND_PREFERENCE_ORDER: &[CompressionKind] =
&[CompressionKind::XZ, CompressionKind::GZip];
static COMPRESSION_KIND_PREFERENCE_ORDER: &[CompressionKind] = &[
CompressionKind::ZStd,
CompressionKind::XZ,
CompressionKind::GZip,
];

impl CompressionKind {
const fn key_prefix(self) -> &'static str {
match self {
Self::GZip => "",
Self::XZ => "xz_",
Self::ZStd => "zst_",
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/dist/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use retry::delay::NoDelay;
use retry::{retry, OperationResult};

use crate::config::PgpPublicKey;
use crate::dist::component::{Components, Package, TarGzPackage, TarXzPackage, Transaction};
use crate::dist::component::{
Components, Package, TarGzPackage, TarXzPackage, TarZStdPackage, Transaction,
};
use crate::dist::config::Config;
use crate::dist::dist::{Profile, TargetTriple, DEFAULT_DIST_SERVER};
use crate::dist::download::{DownloadCfg, File};
Expand Down Expand Up @@ -238,6 +240,7 @@ impl Manifestation {
};
let gz;
let xz;
let zst;
let reader =
utils::FileReaderWithProgress::new_file(&installer_file, &notification_converter)?;
let package: &dyn Package = match format {
Expand All @@ -249,6 +252,10 @@ impl Manifestation {
xz = TarXzPackage::new(reader, temp_cfg, Some(&notification_converter))?;
&xz
}
CompressionKind::ZStd => {
zst = TarZStdPackage::new(reader, temp_cfg, Some(&notification_converter))?;
&zst
}
};

// If the package doesn't contain the component that the
Expand Down
4 changes: 2 additions & 2 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ info: note that the toolchain 'nightly-{0}' is currently in use (directory overr
}

#[test]
fn rustup_xz() {
fn rustup_zstd() {
setup(&|config| {
set_current_dist_date(config, "2015-01-01");
expect_stderr_ok(
Expand All @@ -335,7 +335,7 @@ fn rustup_xz() {
"nightly",
"--no-self-update",
],
for_host!(r"dist/2015-01-01/rust-std-nightly-{0}.tar.xz"),
for_host!(r"dist/2015-01-01/rust-std-nightly-{0}.tar.zst"),
);
});
}
Expand Down
5 changes: 4 additions & 1 deletion tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ fn bad_sha_on_installer() {
let file = file.unwrap();
let path = file.path();
let filename = path.to_string_lossy();
if filename.ends_with(".tar.gz") || filename.ends_with(".tar.xz") {
if filename.ends_with(".tar.gz")
|| filename.ends_with(".tar.xz")
|| filename.ends_with(".tar.zst")
{
rustup::utils::raw::write_file(&path, "xxx").unwrap();
}
}
Expand Down
Loading