Fixup a cure case where a store path already exists so we never make a symlink (#414)

This commit is contained in:
Ana Hobden 2023-04-12 06:25:24 -07:00 committed by GitHub
parent 045fe5fc5d
commit b3c47227ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 17 deletions

View file

@ -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(())

View file

@ -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));