Skip to content

Commit

Permalink
Add Windows CI test for self-update
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancisMurillo committed May 20, 2023
1 parent 6b86066 commit 053a513
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ jobs:
throw 'error on rg.exe'
}
- if: matrix.os == 'windows-latest'
name: "Integration test: [windows] [sync-self]"
env:
SYNC_DIR: "sync-self"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir sync-self
copy "target\debug\tool.exe" "sync-self\tool.exe"
$output = sync-self\tool.exe --config="tests\sync-self-downgrade.toml" sync
if ($output -notmatch 'Successfully installed 1 tool!') {
throw 'error on tool.exe'
}
$old_version = sync-self\tool.exe --version
if ($old_version -notmatch 'tool-sync 0.2.0') {
throw 'self-update is not the same'
}
- if: matrix.os != 'windows-latest'
name: "Integration test: [unix] [sync-full]"
env:
Expand Down
23 changes: 20 additions & 3 deletions src/sync/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use super::progress::SyncProgress;

pub struct Installer<'a> {
store_directory: &'a Path,
self_exe: PathBuf,
tmp_dir: TempDir,
sync_progress: SyncProgress,
}
Expand All @@ -34,6 +35,7 @@ impl<'a> Installer<'a> {
}
Ok(tmp_dir) => Installer {
store_directory,
self_exe: env::current_exe().unwrap(),
tmp_dir,
sync_progress,
},
Expand Down Expand Up @@ -89,7 +91,12 @@ impl<'a> Installer<'a> {
Err(unpack_err.to_string().into())
}
Ok(tool_path) => {
copy_file(tool_path, self.store_directory, &tool_asset.exe_name)?;
copy_file(
tool_path,
self.store_directory,
&tool_asset.exe_name,
&self.self_exe,
)?;

Ok(())
}
Expand All @@ -98,14 +105,24 @@ impl<'a> Installer<'a> {
}
}

fn copy_file(tool_path: PathBuf, store_directory: &Path, exe_name: &str) -> std::io::Result<()> {
fn copy_file(
tool_path: PathBuf,
store_directory: &Path,
exe_name: &str,
self_path: &Path,
) -> std::io::Result<()> {
let exe_name = mk_exe_name(exe_name);

let mut install_path = PathBuf::new();
install_path.push(store_directory);
install_path.push(exe_name);

if &install_path == &env::current_exe()? {
// DANGER: This check does not really mean two paths resolve to the
// same file. For example, the exe path /a/b/c.exe is not the same
// as install path b/c.exe if the current working directory is in /d
// instead of /a. Perhaps expand store directory to absolute or use
// `BurntSushi/same-file`?
if self_path.ends_with(&install_path) {
// May have issues with a symbolic links. The assumption is that
// the store directory is in the PATH and the executable itself
// where this issue should not apply but may be an edge case.
Expand Down
4 changes: 4 additions & 0 deletions tests/sync-self-downgrade.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
store_directory = "sync-self"

[tool-sync]
tag = "v0.2.0"

0 comments on commit 053a513

Please sign in to comment.