Skip to content

Commit

Permalink
Merge pull request #69 from t-mw/patch-3
Browse files Browse the repository at this point in the history
Fix issues updating Windows binaries on non-C: drives.
  • Loading branch information
jaemk committed Feb 24, 2021
2 parents 38488da + b85efb2 commit 96d7171
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [unreleased]
### Added
### Changed
- Fix issues updating Windows binaries on non-`C:` drives.
### Removed

## [0.24.0]
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,10 @@ impl<'a> Move<'a> {
}
Some(temp) => {
if dest.exists() {
fs::rename(dest, temp)?;
// Copy the destination file rather than renaming it, so that
// if it is a running executable the temp file can be removed
// on Windows while the executable is running.
fs::copy(dest, temp)?;
if let Err(e) = fs::rename(self.source, dest) {
fs::rename(temp, dest)?;
return Err(Error::from(e));
Expand Down
10 changes: 4 additions & 6 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,10 @@ pub trait ReleaseUpdate {
confirm("Do you want to continue? [Y/n] ")?;
}

let tmp_dir_parent = if cfg!(windows) {
env::var_os("TEMP").map(PathBuf::from)
} else {
bin_install_path.parent().map(PathBuf::from)
}
.ok_or_else(|| Error::Update("Failed to determine parent dir".into()))?;
let tmp_dir_parent = bin_install_path
.parent()
.map(PathBuf::from)
.ok_or_else(|| Error::Update("Failed to determine parent dir".into()))?;
let tmp_dir = tempfile::Builder::new()
.prefix(&format!("{}_download", bin_name))
.tempdir_in(tmp_dir_parent)?;
Expand Down

0 comments on commit 96d7171

Please sign in to comment.