Offer users better error if fstab entries exist (#241)

* Offer users better error if fstab entries exist

* Split up errors

* Remove a naughty bracket

* last nits
This commit is contained in:
Ana Hobden 2023-02-10 14:44:39 -08:00 committed by GitHub
parent fc13c1d250
commit e3d06c24e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,9 +37,18 @@ impl CreateFstabEntry {
.await
.map_err(|e| ActionError::Read(fstab_path.to_path_buf(), e))?;
let prelude_comment = fstab_prelude_comment(&apfs_volume_label);
// See if the user already has a `/nix` related entry, if so, invite them to remove it.
if fstab_buf.split(&[' ', '\t']).any(|chunk| chunk == "/nix") {
return Err(ActionError::Custom(Box::new(
CreateFstabEntryError::NixEntryExists,
)));
}
// See if a previous install from this crate exists, if so, invite the user to remove it (we may need to change it)
if fstab_buf.contains(&prelude_comment) {
return Err(ActionError::Custom(Box::new(
CreateFstabEntryError::EntryExists(apfs_volume_label.clone()),
CreateFstabEntryError::VolumeEntryExists(apfs_volume_label.clone()),
)));
}
}
@ -193,8 +202,10 @@ fn fstab_entry(uuid: &Uuid, apfs_volume_label: &str) -> String {
#[derive(thiserror::Error, Debug)]
pub enum CreateFstabEntryError {
#[error("An `/etc/fstab` entry for the volume labelled `{0}` already exists. If a Nix Store already exists it may need to be deleted with `diskutil apfs deleteVolume \"{0}\") and should be removed from `/etc/fstab`")]
EntryExists(String),
#[error("An `/etc/fstab` entry for the `/nix` path already exists, consider removing the entry for `/nix`d from `/etc/fstab`")]
NixEntryExists,
#[error("An `/etc/fstab` entry created by `nix-installer` already exists. If a volume named `{0}` already exists, it may need to be deleted with `diskutil apfs deleteVolume \"{0}\" and the entry for `/nix` should be removed from `/etc/fstab`")]
VolumeEntryExists(String),
}
#[derive(Deserialize, Clone, Debug)]