diff --git a/ci-scripts/tests.sh b/ci-scripts/tests.sh index 29468795..a83e797e 100755 --- a/ci-scripts/tests.sh +++ b/ci-scripts/tests.sh @@ -2,8 +2,8 @@ set -euxo pipefail -bins="cargo-deb cargo-llvm-cov cargo-binstall" -test_bins="cargo-deb cargo-llvm-cov" +bins="cargo-llvm-cov cargo-binstall" +test_bins="cargo-llvm-cov" unset CARGO_INSTALL_ROOT unset CARGO_HOME diff --git a/src/bins.rs b/src/bins.rs index 7240707a..f7d2041c 100644 --- a/src/bins.rs +++ b/src/bins.rs @@ -79,7 +79,10 @@ impl BinFile { } pub fn install_bin(&self) -> Result<(), BinstallError> { - // TODO: check if file already exists + if !self.source.try_exists()? { + return Err(BinstallError::BinFileNotFound(self.source.clone())); + } + debug!( "Atomically install file from '{}' to '{}'", self.source.display(), diff --git a/src/errors.rs b/src/errors.rs index 8d336dd4..d4a03120 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,4 +1,7 @@ -use std::process::{ExitCode, ExitStatus, Termination}; +use std::{ + path::PathBuf, + process::{ExitCode, ExitStatus, Termination}, +}; use compact_str::CompactString; use log::{error, warn}; @@ -265,6 +268,14 @@ pub enum BinstallError { )] NoViableTargets, + /// Bin file is not found. + /// + /// - Code: `binstall::binfile` + /// - Exit: 88 + #[error("bin file {0} not found")] + #[diagnostic(severity(error), code(binstall::binfile))] + BinFileNotFound(PathBuf), + /// A wrapped error providing the context of which crate the error is about. #[error("for crate {crate_name}")] CrateContext { @@ -298,6 +309,7 @@ impl BinstallError { OverrideOptionUsedWithMultiInstall { .. } => 85, UnspecifiedBinaries => 86, NoViableTargets => 87, + BinFileNotFound(_) => 88, CrateContext { error, .. } => error.exit_number(), }; diff --git a/src/helpers.rs b/src/helpers.rs index b1b67ddf..0742c1f2 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -271,8 +271,8 @@ pub fn atomic_install(src: &Path, dst: &Path) -> io::Result<()> { dst.display() ); - if fs::rename(src, dst).is_err() { - debug!("Attempting at atomically failed, fallback to creating tempfile."); + if let Err(err) = fs::rename(src, dst) { + debug!("Attempting at atomically failed: {err:#?}, fallback to creating tempfile."); // src and dst is not on the same filesystem/mountpoint. // Fallback to creating NamedTempFile on the parent dir of // dst.