cargo-binstall/e2e-tests/self-upgrade-no-symlink.sh
Jiahao XU ab4da7f059
Fix self-update on windows (#712)
Fixed #702


* Add new dep windows v0.44.0 for windows only
* Add regression test for #702
* Impl `win::replace_file`
* Use `ReplaceFileW` on windows if `fs::rename` in `fs::atomic_install` fails
* Improve logging and err messages
* Add more regression tests
* Make `BinFile::install_link` atomic: Do not remove file if dst exists
* Fallback to `ReplaceFileW` in `fs::atomic_symlink_file`
* Refactor: Extract new fn `fs::persist`
* Use `fs::persist` instead of `TempFile::persist` in `fs::atomic_install`, which fallbacks to `ReplaceFileW` on windows

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Co-authored-by: Félix Saparelli <felix@passcod.name>
2023-01-17 18:05:07 +11:00

32 lines
933 B
Bash

#!/bin/bash
set -euxo pipefail
unset CARGO_INSTALL_ROOT
export CARGO_HOME=$(mktemp -d 2>/dev/null || mktemp -d -t 'cargo-home')
export PATH="$CARGO_HOME/bin:$PATH"
# first boostrap-install into the CARGO_HOME
mkdir -p "$CARGO_HOME/bin"
cp "./$1" "$CARGO_HOME/bin"
# now we're running the CARGO_HOME/bin/cargo-binstall (via cargo):
# self update replacing no-symlinks with no-symlinks
cargo binstall --no-confirm --no-symlinks --force cargo-binstall
# self update replacing no-symlinks with symlinks
cp "./$1" "$CARGO_HOME/bin"
cargo binstall --no-confirm --force cargo-binstall
# self update replacing symlinks with symlinks
ln -snf "$(pwd)/cargo-binstall" "$CARGO_HOME/bin/cargo-binstall"
cargo binstall --no-confirm --force cargo-binstall
# self update replacing symlinks with no-symlinks
ln -snf "$(pwd)/cargo-binstall" "$CARGO_HOME/bin/cargo-binstall"
cargo binstall --no-confirm --force --no-symlinks cargo-binstall