Skip to content

Commit

Permalink
fix: create toolchain directory atomically
Browse files Browse the repository at this point in the history
  • Loading branch information
Kha committed Feb 7, 2024
1 parent 1fa3f6e commit 008b19c
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/elan-dist/src/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,39 @@ impl Manifestation {

notify_handler(Notification::InstallingComponent("lean"));

// unpack into temporary place, then move atomically to guard against aborts during unpacking
let unpack_dir = prefix.with_extension("tmp");

// Remove old files
if utils::is_directory(prefix) {
utils::remove_dir("toolchain directory", prefix, &|n| {
(notify_handler)(n.into())
})?;
}

utils::ensure_dir_exists("toolchain directory", prefix, &|n| {
if utils::is_directory(&unpack_dir) {
utils::remove_dir("temp toolchain directory", &unpack_dir, &|n| {
(notify_handler)(n.into())
})?;
}

utils::ensure_dir_exists("temp toolchain directory", &unpack_dir, &|n| {
(notify_handler)(n.into())
})?;

// Extract new files
if url.ends_with(".tar.gz") {
TarGzPackage::unpack_file(&installer_file, prefix)?
TarGzPackage::unpack_file(&installer_file, &unpack_dir)?
} else if url.ends_with(".tar.zst") {
TarZstdPackage::unpack_file(&installer_file, prefix)?
TarZstdPackage::unpack_file(&installer_file, &unpack_dir)?
} else if url.ends_with(".zip") {
ZipPackage::unpack_file(&installer_file, prefix)?
ZipPackage::unpack_file(&installer_file, &unpack_dir)?
} else {
return Err(format!("unsupported archive format: {}", url).into())
}

utils::rename_dir("temp toolchain directory", &unpack_dir, prefix)?;

Ok(())
}
}

0 comments on commit 008b19c

Please sign in to comment.