Skip to content

Commit

Permalink
Adjust "windows-sys" usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dylni committed Dec 3, 2022
1 parent 451777f commit 82e184d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ print_bytes = { version = "0.7", optional = true }
serde = { version = "1.0", optional = true }

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.42", features = ["Win32_Foundation", "Win32_Storage_FileSystem"] }
windows-sys = { version = "0.42", features = ["Win32_Storage_FileSystem"] }

[dev-dependencies]
bincode = "1.3"
tempfile = "3.2"
windows-sys = { version = "0.42", features = ["Win32_Foundation"] }

[target.'cfg(not(windows))'.dev-dependencies]
libc = "0.2"
Expand Down
3 changes: 2 additions & 1 deletion src/windows/localize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::os::windows::ffi::OsStrExt;
use std::os::windows::ffi::OsStringExt;
use std::path::Path;

use windows_sys::Win32::UI::Shell::{SHGetFileInfoW, SHGFI_DISPLAYNAME};
use windows_sys::Win32::UI::Shell::SHGetFileInfoW;
use windows_sys::Win32::UI::Shell::SHGFI_DISPLAYNAME;

pub(super) fn name(path: &Path) -> Option<OsString> {
let mut path: Vec<_> = path.as_os_str().encode_wide().collect();
Expand Down
11 changes: 11 additions & 0 deletions src/windows/normalize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::env;
use std::ffi::OsString;
use std::io;
use std::mem;
use std::os::windows::ffi::OsStrExt;
use std::os::windows::ffi::OsStringExt;
use std::path::Component;
Expand All @@ -15,6 +16,12 @@ use windows_sys::Win32::Storage::FileSystem::GetFullPathNameW;
use super::BasePath;
use super::BasePathBuf;

macro_rules! static_assert {
( $condition:expr ) => {
const _: () = assert!($condition, "static assertion failed");
};
}

const SEPARATOR: u16 = b'\\' as _;

pub(super) fn is_base(path: &Path) -> bool {
Expand Down Expand Up @@ -96,6 +103,10 @@ pub(super) fn normalize_virtually(
break Err(io::Error::last_os_error());
}

let _: u32 = capacity;
// This assertion should never fail.
static_assert!(mem::size_of::<u32>() <= mem::size_of::<usize>());

let length = capacity as usize;
if let Some(mut additional_capacity) =
length.checked_sub(buffer.capacity())
Expand Down

0 comments on commit 82e184d

Please sign in to comment.