Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenByteDev committed Dec 9, 2022
1 parent 11a958a commit 9f48ff7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
6 changes: 4 additions & 2 deletions burnt-sushi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#![allow(clippy::module_inception, non_snake_case)]
#![windows_subsystem = "windows"]

use anyhow::{anyhow, Context};
use dll_syringe::process::{OwnedProcess, Process};
use log::{debug, error, info, trace, warn};
use anyhow::{anyhow, Context};
use winapi::{
shared::minwindef::FALSE,
um::{processthreadsapi::OpenProcess, synchapi::WaitForSingleObject, winnt::PROCESS_TERMINATE},
Expand Down Expand Up @@ -173,7 +173,9 @@ async fn handle_install() -> anyhow::Result<()> {
.parent()
.ok_or_else(|| anyhow!("Failed to determine parent directory"))?
.join(DEFAULT_BLOCKER_FILE_NAME);
resolver::resolve_blocker(Some(&blocker_location)).await.context("Failed to write blocker to disk")?;
resolver::resolve_blocker(Some(&blocker_location))
.await
.context("Failed to write blocker to disk")?;

Ok(())
}
Expand Down
29 changes: 19 additions & 10 deletions burnt-sushi/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use widestring::U16CString;
use winapi::um::{shellapi::ShellExecuteW, winuser::SW_SHOWDEFAULT};
use winrt_toast::{Action, Text, Toast, ToastManager};

use crate::{APP_NAME, ARGS, APP_VERSION};
use crate::{APP_NAME, APP_VERSION, ARGS};

pub async fn update() -> anyhow::Result<bool> {
let releases = tokio::task::spawn_blocking(load_releases)
Expand Down Expand Up @@ -82,7 +82,11 @@ pub async fn update() -> anyhow::Result<bool> {
.tempdir()
.context("Failed to create temporary directory")?;
let tmp_bin_path = tmp_dir.path().join(&asset.name);
let tmp_bin = File::create(&tmp_bin_path).await.context("Error creating temporary file")?.into_std().await;
let tmp_bin = File::create(&tmp_bin_path)
.await
.context("Error creating temporary file")?
.into_std()
.await;

tokio::task::spawn_blocking(move || download_file(&asset.download_url, tmp_bin))
.await
Expand All @@ -93,15 +97,20 @@ pub async fn update() -> anyhow::Result<bool> {

let moved_bin = current_exe.with_extension("exe.bak");

fs::rename(&current_exe, &moved_bin).await.context("Failed to move current executable")?;
fs::rename(&current_exe, &moved_bin)
.await
.context("Failed to move current executable")?;
match fs::rename(&tmp_bin_path, &current_exe).await {
Ok(_) => {}
Err(e) if e.raw_os_error() == Some(17) => {
fs::copy(&tmp_bin_path, &current_exe)
.await
.context("Failed to copy updated executable to current executable path")?;
}
Err(e) => return Err(e).context("Failed to move updated executable to current executable path")?,
Err(e) => {
return Err(e)
.context("Failed to move updated executable to current executable path")?
}
}

debug!("Switched out binary");
Expand All @@ -128,12 +137,12 @@ fn restart(new_exe: &Path, old_exe: &Path) -> anyhow::Result<()> {

fn restart_elevated() -> anyhow::Result<()> {
let exe = U16CString::from_os_str(
env::current_exe().context("Failed to locate current executable")?.into_os_string()
).context("Current executable has an invalid path?")?;
let current_args = env::args()
.skip(1)
.collect::<Vec<_>>()
.join(" ");
env::current_exe()
.context("Failed to locate current executable")?
.into_os_string(),
)
.context("Current executable has an invalid path?")?;
let current_args = env::args().skip(1).collect::<Vec<_>>().join(" ");
let new_args = "--update-elevate-restart --singleton-wait-for-shutdown";
let args = U16CString::from_str(format!("{current_args} {new_args}"))
.context("Arguments contain invalid characters")?;
Expand Down

0 comments on commit 9f48ff7

Please sign in to comment.