Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
InfyniteHeap committed Sep 24, 2024
1 parent ce0fedc commit 00db126
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions src/cli/self_update/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env::{consts::EXE_SUFFIX, split_paths};
use std::ffi::{OsStr, OsString};
use std::fmt;
use std::io::Write;
use std::ops::Deref;
use std::os::windows::ffi::OsStrExt;
use std::path::Path;
use std::process::Command;
Expand Down Expand Up @@ -530,9 +531,8 @@ fn _add_to_path(old_path: HSTRING, path_str: HSTRING) -> Option<HSTRING> {
if old_path.is_empty() {
Some(path_str)
} else if old_path
.as_wide()
.windows(path_str.len())
.any(|path| path == path_str.as_wide())
.any(|path| path == path_str.deref())
{
None
} else {
Expand All @@ -546,20 +546,19 @@ fn _add_to_path(old_path: HSTRING, path_str: HSTRING) -> Option<HSTRING> {
// Returns None if the existing old_path does not need changing
fn _remove_from_path(old_path: HSTRING, path_str: HSTRING) -> Option<HSTRING> {
let idx = old_path
.as_wide()
.windows(path_str.len())
.position(|path| path == path_str.as_wide())?;
.position(|path| path == path_str.deref())?;
// If there's a trailing semicolon (likely, since we probably added one
// during install), include that in the substring to remove. We don't search
// for that to find the string, because if it's the last string in the path,
// there may not be.
let mut len = path_str.len();
if old_path.as_wide().get(idx + path_str.len()) == Some(&(b';' as u16)) {
if old_path.get(idx + path_str.len()) == Some(&(b';' as u16)) {
len += 1;
}

let mut new_path = old_path.as_wide()[..idx].to_owned();
new_path.extend_from_slice(&old_path.as_wide()[idx + len..]);
let mut new_path = old_path[..idx].to_owned();
new_path.extend_from_slice(&old_path[idx + len..]);
// Don't leave a trailing ; though, we don't want an empty string in the
// path.
if new_path.last() == Some(&(b';' as u16)) {
Expand Down

0 comments on commit 00db126

Please sign in to comment.