diff --git a/src/action/base/move_unpacked_nix.rs b/src/action/base/move_unpacked_nix.rs index e967aa0..a36f9a1 100644 --- a/src/action/base/move_unpacked_nix.rs +++ b/src/action/base/move_unpacked_nix.rs @@ -93,24 +93,27 @@ impl Action for MoveUnpackedNix { { let entry_dest = dest_store.join(entry.file_name()); if entry_dest.exists() { - tracing::trace!(src = %entry.path().display(), dest = %entry_dest.display(), "Skipping, already exists"); - } else { - tracing::trace!(src = %entry.path().display(), dest = %entry_dest.display(), "Renaming"); - tokio::fs::rename(&entry.path(), &entry_dest) + tracing::trace!(src = %entry.path().display(), dest = %entry_dest.display(), "Removing already existing package"); + tokio::fs::remove_dir_all(&entry_dest) .await - .map_err(|e| { - ActionErrorKind::Rename(entry.path().clone(), entry_dest.to_owned(), e) - }) - .map_err(Self::error)?; - // Leave a back link where we copied from since later we may need to know which packages we actually transferred - // eg, know which `nix` version we installed when curing a user with several versions installed - tokio::fs::symlink(&entry_dest, entry.path()) - .await - .map_err(|e| { - ActionErrorKind::Symlink(entry_dest.to_owned(), entry.path().clone(), e) - }) + .map_err(|e| ActionErrorKind::Remove(entry_dest.clone(), e)) .map_err(Self::error)?; } + tracing::trace!(src = %entry.path().display(), dest = %entry_dest.display(), "Renaming"); + tokio::fs::rename(&entry.path(), &entry_dest) + .await + .map_err(|e| { + ActionErrorKind::Rename(entry.path().clone(), entry_dest.to_owned(), e) + }) + .map_err(Self::error)?; + // Leave a back link where we copied from since later we may need to know which packages we actually transferred + // eg, know which `nix` version we installed when curing a user with several versions installed + tokio::fs::symlink(&entry_dest, entry.path()) + .await + .map_err(|e| { + ActionErrorKind::Symlink(entry_dest.to_owned(), entry.path().clone(), e) + }) + .map_err(Self::error)?; } Ok(()) diff --git a/src/action/base/setup_default_profile.rs b/src/action/base/setup_default_profile.rs index b13f75f..0f4447f 100644 --- a/src/action/base/setup_default_profile.rs +++ b/src/action/base/setup_default_profile.rs @@ -73,7 +73,7 @@ impl Action for SetupDefaultProfile { let nix_pkg = if let Some(nix_pkg) = found_nix_pkg { tokio::fs::read_link(&nix_pkg) .await - .map_err(|e| ActionErrorKind::Canonicalize(nix_pkg, e)) + .map_err(|e| ActionErrorKind::ReadSymlink(nix_pkg, e)) .map_err(Self::error)? } else { return Err(Self::error(SetupDefaultProfileError::NoNix)); @@ -106,7 +106,7 @@ impl Action for SetupDefaultProfile { let nss_ca_cert_pkg = if let Some(nss_ca_cert_pkg) = found_nss_ca_cert_pkg { tokio::fs::read_link(&nss_ca_cert_pkg) .await - .map_err(|e| ActionErrorKind::Canonicalize(nss_ca_cert_pkg, e)) + .map_err(|e| ActionErrorKind::ReadSymlink(nss_ca_cert_pkg, e)) .map_err(Self::error)? } else { return Err(Self::error(SetupDefaultProfileError::NoNssCacert));