fix(setup): make a new setup use an image of its build this computer already holds instead of downloading one

This commit is contained in:
Tyler Smith committed 2026-11-11 23:24:42 -05:00
1 parent eebea73a93
commit fe36b4f29f
3 files changed
+68

No files matched your search

+18
View File
@@ -1043,6 +1043,24 @@ pub(super) fn setup(environment: &Environment<'_>, mut command: Request) -> Resu
}
// Every new or resumed setup knows its installer from here on.
let install_image = command.install_image.unwrap_or(InstallImage::Network);
// An image of the build this computer holds already, downloaded by an
// earlier command or by another user under sudo, serves as --ipsw.
if command.ipsw.is_none()
&& command.fetch
&& let Some(path) = super::sources::cached_image(
environment,
match install_image {
InstallImage::Full => super::sources::Need::WholeImage,
InstallImage::Network => super::sources::Need::BootFiles,
},
&command.build,
command.model(),
command.download_dir.as_deref(),
)
{
command.ipsw = Some(path);
command.fetch = false;
}
// Downloaded boot archives are kept in one place until setup finishes,
// so a setup run again after a stop reuses them, and removed once it
// has. A full image goes directly to the USB after preparation and
+24
View File
@@ -371,6 +371,30 @@ pub(super) fn obtain(
}
}
/// An image this computer holds that serves `need` for `build` and `model`
/// (`--download-dir` first, then every cache [`image_caches`] names): a new
/// setup takes it as `--ipsw` instead of downloading.
pub(super) fn cached_image(
environment: &Environment<'_>,
need: Need,
build: &str,
model: &str,
download_dir: Option<&Path>,
) -> Option<PathBuf> {
let lookup = Lookup {
need,
build,
model,
ipsw: None,
download_dir,
medium: None,
};
lookup
.directories(environment)
.iter()
.find_map(|directory| cached(directory, &lookup))
}
/// A complete image of `lookup`'s build and model in `directory`, or for
/// boot files also a boot archive: the one a command downloaded, or the
/// one a first setup left.
+26
View File
@@ -2633,6 +2633,32 @@ fn os_update_checks_everything_before_any_download() {
assert_eq!((snapshot(&f.esp), snapshot(&stela_volume(&f))), before);
}
#[test]
fn a_new_setup_takes_an_image_this_computer_holds_instead_of_downloading() {
for installer in [InstallImage::Full, InstallImage::Network] {
let mut f = fixture(64 * GIB, false);
add_stela(&mut f);
let cache = f._dir.path().join("cache");
fs::create_dir_all(&cache).unwrap();
let cached = cache.join(format!(
"UniversalMac_0_{}_Restore.ipsw",
restore::payload::SYNTHETIC_BUILD
));
fs::copy(&f.ipsw, &cached).unwrap();
let mut request = command(&f, &f.esp);
request.ipsw = None;
request.fetch = true;
request.download_dir = Some(cache.clone());
request.install_image = Some(installer);
let text = setup(&environment(&f.host), request).unwrap();
assert!(
text.contains(&format!("restore image {}", cached.display())),
"{text}"
);
assert_eq!(record(&f).install_kind(), installer);
}
}
#[test]
fn repair_of_a_short_piece_downloads_the_boot_files_and_that_piece_saying_so() {
let mut f = fixture(64 * GIB, false);