Skip to content

Commit 9d34fd5

Browse files
committed
Propagate use of DistOptions
1 parent 87a37ce commit 9d34fd5

File tree

1 file changed

+29
-47
lines changed

1 file changed

+29
-47
lines changed

src/dist/mod.rs

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -750,25 +750,7 @@ pub(crate) async fn update_from_dist(
750750
}
751751
}
752752

753-
let res = update_from_dist_(
754-
opts.dl_cfg,
755-
opts.update_hash,
756-
opts.desc,
757-
match opts.exists {
758-
true => None,
759-
false => Some(opts.profile),
760-
},
761-
prefix,
762-
opts.force,
763-
opts.allow_downgrade,
764-
opts.old_date_version
765-
.as_ref()
766-
.map(|(date, _)| date.as_str()),
767-
opts.components,
768-
opts.targets,
769-
)
770-
.await;
771-
753+
let res = update_from_dist_(prefix, opts).await;
772754
// Don't leave behind an empty / broken installation directory
773755
if res.is_err() && fresh_install {
774756
// FIXME Ignoring cascading errors
@@ -779,29 +761,21 @@ pub(crate) async fn update_from_dist(
779761
}
780762

781763
async fn update_from_dist_(
782-
download: DownloadCfg<'_>,
783-
update_hash: Option<&Path>,
784-
toolchain: &ToolchainDesc,
785-
profile: Option<Profile>,
786764
prefix: &InstallPrefix,
787-
force_update: bool,
788-
allow_downgrade: bool,
789-
old_date: Option<&str>,
790-
components: &[&str],
791-
targets: &[&str],
765+
opts: &DistOptions<'_>,
792766
) -> Result<Option<String>> {
793-
let mut toolchain = toolchain.clone();
794767
let mut fetched = String::new();
795768
let mut first_err = None;
796-
let backtrack = toolchain.channel == "nightly" && toolchain.date.is_none();
769+
let backtrack = opts.desc.channel == "nightly" && opts.desc.date.is_none();
797770
// We want to limit backtracking if we do not already have a toolchain
798-
let mut backtrack_limit: Option<i32> = if toolchain.date.is_some() {
771+
let mut backtrack_limit: Option<i32> = if opts.desc.date.is_some() {
799772
None
800773
} else {
801774
// We limit the backtracking to 21 days by default (half a release cycle).
802775
// The limit of 21 days is an arbitrary selection, so we let the user override it.
803776
const BACKTRACK_LIMIT_DEFAULT: i32 = 21;
804-
let provided = download
777+
let provided = opts
778+
.dl_cfg
805779
.process
806780
.var("RUSTUP_BACKTRACK_LIMIT")
807781
.ok()
@@ -820,30 +794,36 @@ async fn update_from_dist_(
820794
// We could arguably use the date of the first rustup release here, but that would break a
821795
// bunch of the tests, which (inexplicably) use 2015-01-01 as their manifest dates.
822796
let first_manifest = date_from_manifest_date("2014-12-20").unwrap();
823-
let old_manifest = old_date
824-
.and_then(date_from_manifest_date)
797+
let old_manifest = opts
798+
.old_date_version
799+
.as_ref()
800+
.and_then(|(d, _)| date_from_manifest_date(d))
825801
.unwrap_or(first_manifest);
826-
let last_manifest = if allow_downgrade {
802+
let last_manifest = if opts.allow_downgrade {
827803
first_manifest
828804
} else {
829805
old_manifest
830806
};
831807

832808
let current_manifest = {
833-
let manifestation = Manifestation::open(prefix.clone(), toolchain.target.clone())?;
809+
let manifestation = Manifestation::open(prefix.clone(), opts.desc.target.clone())?;
834810
manifestation.load_manifest()?
835811
};
836812

813+
let mut toolchain = opts.desc.clone();
837814
loop {
838815
match try_update_from_dist_(
839-
download,
840-
update_hash,
816+
opts.dl_cfg,
817+
opts.update_hash,
841818
&toolchain,
842-
profile,
819+
match opts.exists {
820+
false => Some(opts.profile),
821+
true => None,
822+
},
843823
prefix,
844-
force_update,
845-
components,
846-
targets,
824+
opts.force,
825+
opts.components,
826+
opts.targets,
847827
&mut fetched,
848828
)
849829
.await
@@ -857,11 +837,13 @@ async fn update_from_dist_(
857837
let cause = e.downcast_ref::<DistError>();
858838
match cause {
859839
Some(DistError::ToolchainComponentsMissing(components, manifest, ..)) => {
860-
(download.notify_handler)(Notification::SkippingNightlyMissingComponent(
861-
&toolchain,
862-
current_manifest.as_ref().unwrap_or(manifest),
863-
components,
864-
));
840+
(opts.dl_cfg.notify_handler)(
841+
Notification::SkippingNightlyMissingComponent(
842+
&toolchain,
843+
current_manifest.as_ref().unwrap_or(manifest),
844+
components,
845+
),
846+
);
865847

866848
if first_err.is_none() {
867849
first_err = Some(e);

0 commit comments

Comments
 (0)