Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Aug 26, 2024
1 parent 8a3be6e commit df9d0eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/bootstrap/src/chrisdenton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ pub fn delete_with_info(path: &Path) -> Result<(), NTSTATUS> {
Ok(())
}

pub fn last_nt_status() -> NTSTATUS {
unsafe { RtlGetLastNtStatus() }
}

#[repr(C)]
pub struct UNICODE_STRING {
pub Length: u16,
Expand Down Expand Up @@ -122,7 +126,7 @@ const FileDispositionInformationEx: i32 = 64;
const FILE_DISPOSITION_DELETE: u32 = 1;
const FILE_DISPOSITION_POSIX_SEMANTICS: u32 = 2;
const FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE: u32 = 0x10;
const STATUS_OBJECT_NAME_NOT_FOUND: NTSTATUS = 0xC0000034_u32 as _;
pub const STATUS_OBJECT_NAME_NOT_FOUND: NTSTATUS = 0xC0000034_u32 as _;
//const STATUS_OBJECT_NAME_INVALID: NTSTATUS = 0xC0000033_u32 as _;

#[link(name = "ntdll", kind = "raw-dylib")]
Expand All @@ -149,6 +153,7 @@ extern "system" {
Length: u32,
FileInformationClass: i32,
) -> NTSTATUS;
fn RtlGetLastNtStatus() -> NTSTATUS;
}
#[link(name = "kernel32", kind = "raw-dylib")]
extern "system" {
Expand Down
8 changes: 7 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,13 @@ Executed at: {executed_at}"#,
#[cfg(not(windows))]
let _ = fs::remove_file(dst);
#[cfg(windows)]
let _ = chrisdenton::delete_with_info(dst);
if fs::remove_file(dst).is_err() {
let status = chrisdenton::last_nt_status();
if status != chrisdenton::STATUS_OBJECT_NAME_NOT_FOUND {
println!("remove_file failed: {status:#X}");
let _ = chrisdenton::delete_with_info(dst);
}
}

let metadata = t!(src.symlink_metadata(), format!("src = {}", src.display()));
let mut src = src.to_path_buf();
Expand Down

0 comments on commit df9d0eb

Please sign in to comment.