mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-25 21:22:55 +00:00
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:
parent
763d4610e5
commit
bf700f9012
4 changed files with 21 additions and 6 deletions
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
bins="cargo-deb cargo-llvm-cov cargo-binstall"
|
bins="cargo-llvm-cov cargo-binstall"
|
||||||
test_bins="cargo-deb cargo-llvm-cov"
|
test_bins="cargo-llvm-cov"
|
||||||
|
|
||||||
unset CARGO_INSTALL_ROOT
|
unset CARGO_INSTALL_ROOT
|
||||||
unset CARGO_HOME
|
unset CARGO_HOME
|
||||||
|
|
|
@ -79,7 +79,10 @@ impl BinFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn install_bin(&self) -> Result<(), BinstallError> {
|
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!(
|
debug!(
|
||||||
"Atomically install file from '{}' to '{}'",
|
"Atomically install file from '{}' to '{}'",
|
||||||
self.source.display(),
|
self.source.display(),
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use std::process::{ExitCode, ExitStatus, Termination};
|
use std::{
|
||||||
|
path::PathBuf,
|
||||||
|
process::{ExitCode, ExitStatus, Termination},
|
||||||
|
};
|
||||||
|
|
||||||
use compact_str::CompactString;
|
use compact_str::CompactString;
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
|
@ -265,6 +268,14 @@ pub enum BinstallError {
|
||||||
)]
|
)]
|
||||||
NoViableTargets,
|
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.
|
/// A wrapped error providing the context of which crate the error is about.
|
||||||
#[error("for crate {crate_name}")]
|
#[error("for crate {crate_name}")]
|
||||||
CrateContext {
|
CrateContext {
|
||||||
|
@ -298,6 +309,7 @@ impl BinstallError {
|
||||||
OverrideOptionUsedWithMultiInstall { .. } => 85,
|
OverrideOptionUsedWithMultiInstall { .. } => 85,
|
||||||
UnspecifiedBinaries => 86,
|
UnspecifiedBinaries => 86,
|
||||||
NoViableTargets => 87,
|
NoViableTargets => 87,
|
||||||
|
BinFileNotFound(_) => 88,
|
||||||
CrateContext { error, .. } => error.exit_number(),
|
CrateContext { error, .. } => error.exit_number(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -271,8 +271,8 @@ pub fn atomic_install(src: &Path, dst: &Path) -> io::Result<()> {
|
||||||
dst.display()
|
dst.display()
|
||||||
);
|
);
|
||||||
|
|
||||||
if fs::rename(src, dst).is_err() {
|
if let Err(err) = fs::rename(src, dst) {
|
||||||
debug!("Attempting at atomically failed, fallback to creating tempfile.");
|
debug!("Attempting at atomically failed: {err:#?}, fallback to creating tempfile.");
|
||||||
// src and dst is not on the same filesystem/mountpoint.
|
// src and dst is not on the same filesystem/mountpoint.
|
||||||
// Fallback to creating NamedTempFile on the parent dir of
|
// Fallback to creating NamedTempFile on the parent dir of
|
||||||
// dst.
|
// dst.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue