Skip to content

Commit

Permalink
Merge pull request #4 from Mart-Bogdan/master
Browse files Browse the repository at this point in the history
Fix bug: high word of size for compressed files on windows was ignored
  • Loading branch information
scullionw authored Dec 13, 2021
2 parents 1d7bb8a + c1e2659 commit c9b26cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dirstat-rs"
version = "0.3.3"
version = "0.3.4"
authors = ["scullionw <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
12 changes: 3 additions & 9 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ use std::io;
use std::iter::once;
use std::os::windows::ffi::OsStrExt;
use std::path::Path;
use std::ptr::null_mut;
use winapi::shared::winerror::NO_ERROR;
use winapi::um::errhandlingapi::GetLastError;
use winapi::um::fileapi::GetCompressedFileSizeW;
use winapi::um::fileapi::INVALID_FILE_SIZE;

pub fn compressed_size(path: &Path) -> Result<u64, Box<dyn Error>> {
let wide: Vec<u16> = path.as_os_str().encode_wide().chain(once(0)).collect();
let high: *mut u32 = null_mut();
let mut high: u32 = 0;

// TODO: Deal with max path size
let low = unsafe { GetCompressedFileSizeW(wide.as_ptr(), high) };
let low = unsafe { GetCompressedFileSizeW(wide.as_ptr(), &mut high) };

if low == INVALID_FILE_SIZE {
let err = get_last_error();
Expand All @@ -25,12 +24,7 @@ pub fn compressed_size(path: &Path) -> Result<u64, Box<dyn Error>> {
}
}

if high.is_null() {
Ok(u64::from(low))
} else {
let high = unsafe { *high };
Ok(u64::from(high) << 32 | u64::from(low))
}
Ok(u64::from(high) << 32 | u64::from(low))
}

fn get_last_error() -> u32 {
Expand Down

0 comments on commit c9b26cc

Please sign in to comment.