Improve err msg when source is missing in BinFile::install_bin (#301)

* Improve err msg in `helpers::atomic_install`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Check for missing `source` in `install_bin`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix `install_bin`: Use `try_exists` instead of `exists`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Do not test `cargo-deb` in `ci-scripts/tests.sh`

Due to the fact that it uses gnu sparse extension which is not supported
by crate `tar`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-08-20 00:25:51 +10:00 committed by GitHub
parent 763d4610e5
commit bf700f9012
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 6 deletions

View file

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

View file

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

View file

@ -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(),
};

View file

@ -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.