feat: Add new cmdline option --no-track (#1111)

Same as `cargo-install`'s `--no-track`.
It is also passed to `cargo-install` if it is invoked.

Also fixed `fs::atomic_symlink_file` which on Windows could fallback to
non-atomic install if symlinking failed.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-06-03 19:15:18 +10:00 committed by GitHub
parent a849db3ef4
commit 1432093dcc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 194 additions and 43 deletions

View file

@ -172,6 +172,21 @@ pub struct Args {
#[clap(help_heading = "Options", long)]
pub no_cleanup: bool,
/// By default, binstall keeps track of the installed packages with metadata files
/// stored in the installation root directory.
///
/// This flag tells binstall not to use or create that file.
///
/// With this flag, binstall will refuse to overwrite any existing files unless the
/// `--force` flag is used.
///
/// This also disables binstalls ability to protect against multiple concurrent
/// invocations of binstall installing at the same time.
///
/// This flag will also be passed to `cargo-install` if it is invoked.
#[clap(help_heading = "Options", long)]
pub no_track: bool,
/// Install binaries in a custom location.
///
/// By default, binaries are installed to the global location `$CARGO_HOME/bin`, and global

View file

@ -59,7 +59,7 @@ pub fn install_crates(
// Compute paths
let cargo_root = args.root;
let (install_path, mut manifests, temp_dir) =
compute_paths_and_load_manifests(cargo_root.clone(), args.install_path)?;
compute_paths_and_load_manifests(cargo_root.clone(), args.install_path, args.no_track)?;
// Remove installed crates
let mut crate_names =
@ -101,6 +101,7 @@ pub fn install_crates(
force: args.force,
quiet: args.log_level == Some(LevelFilter::Off),
locked: args.locked,
no_track: args.no_track,
version_req: args.version_req,
manifest_path: args.manifest_path,
@ -234,6 +235,7 @@ fn read_root_certs(root_certificate_paths: Vec<PathBuf>) -> impl Iterator<Item =
fn compute_paths_and_load_manifests(
roots: Option<PathBuf>,
install_path: Option<PathBuf>,
no_track: bool,
) -> Result<(PathBuf, Option<Manifests>, tempfile::TempDir)> {
// Compute cargo_roots
let cargo_roots = install_path::get_cargo_roots_path(roots).ok_or_else(|| {
@ -251,8 +253,10 @@ fn compute_paths_and_load_manifests(
fs::create_dir_all(&install_path).map_err(BinstallError::Io)?;
debug!("Using install path: {}", install_path.display());
let no_manifests = no_track || custom_install_path;
// Load manifests
let manifests = if !custom_install_path {
let manifests = if !no_manifests {
Some(Manifests::open_exclusive(&cargo_roots)?)
} else {
None