mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
fix/sync ~ update to correct current WinAPI usage (ref #1496)
This commit is contained in:
parent
fc9abdc179
commit
156031b929
2 changed files with 12 additions and 11 deletions
|
@ -16,11 +16,10 @@ path = "src/sync.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getopts = "0.2.18"
|
getopts = "0.2.18"
|
||||||
kernel32-sys = "0.2.2"
|
|
||||||
libc = "0.2.42"
|
libc = "0.2.42"
|
||||||
uucore = { version="0.0.3", package="uucore", git="https://github.com/uutils/uucore.git", branch="canary", features=["wide"] }
|
uucore = { version="0.0.3", package="uucore", git="https://github.com/uutils/uucore.git", branch="canary", features=["wide"] }
|
||||||
uucore_procs = { version="0.0.3", package="uucore_procs", git="https://github.com/uutils/uucore.git", branch="canary" }
|
uucore_procs = { version="0.0.3", package="uucore_procs", git="https://github.com/uutils/uucore.git", branch="canary" }
|
||||||
winapi = { version = "0.3", features = ["handleapi", "winerror"] }
|
winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "std", "winbase", "winerror"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "sync"
|
name = "sync"
|
||||||
|
|
|
@ -36,7 +36,6 @@ mod platform {
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod platform {
|
mod platform {
|
||||||
extern crate kernel32;
|
|
||||||
extern crate winapi;
|
extern crate winapi;
|
||||||
use self::winapi::shared::minwindef;
|
use self::winapi::shared::minwindef;
|
||||||
use self::winapi::shared::winerror;
|
use self::winapi::shared::winerror;
|
||||||
|
@ -50,13 +49,13 @@ mod platform {
|
||||||
|
|
||||||
unsafe fn flush_volume(name: &str) {
|
unsafe fn flush_volume(name: &str) {
|
||||||
let name_wide = name.to_wide_null();
|
let name_wide = name.to_wide_null();
|
||||||
if kernel32::GetDriveTypeW(name_wide.as_ptr()) == winbase::DRIVE_FIXED {
|
if winapi::um::fileapi::GetDriveTypeW(name_wide.as_ptr()) == winbase::DRIVE_FIXED {
|
||||||
let sliced_name = &name[..name.len() - 1]; // eliminate trailing backslash
|
let sliced_name = &name[..name.len() - 1]; // eliminate trailing backslash
|
||||||
match OpenOptions::new().write(true).open(sliced_name) {
|
match OpenOptions::new().write(true).open(sliced_name) {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
if kernel32::FlushFileBuffers(file.as_raw_handle()) == 0 {
|
if winapi::um::fileapi::FlushFileBuffers(file.as_raw_handle()) == 0 {
|
||||||
crash!(
|
crash!(
|
||||||
kernel32::GetLastError() as i32,
|
winapi::um::errhandlingapi::GetLastError() as i32,
|
||||||
"failed to flush file buffer"
|
"failed to flush file buffer"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -72,10 +71,13 @@ mod platform {
|
||||||
unsafe fn find_first_volume() -> (String, winnt::HANDLE) {
|
unsafe fn find_first_volume() -> (String, winnt::HANDLE) {
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = mem::uninitialized();
|
let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = mem::uninitialized();
|
||||||
let handle = kernel32::FindFirstVolumeW(name.as_mut_ptr(), name.len() as minwindef::DWORD);
|
let handle = winapi::um::fileapi::FindFirstVolumeW(
|
||||||
|
name.as_mut_ptr(),
|
||||||
|
name.len() as minwindef::DWORD,
|
||||||
|
);
|
||||||
if handle == handleapi::INVALID_HANDLE_VALUE {
|
if handle == handleapi::INVALID_HANDLE_VALUE {
|
||||||
crash!(
|
crash!(
|
||||||
kernel32::GetLastError() as i32,
|
winapi::um::errhandlingapi::GetLastError() as i32,
|
||||||
"failed to find first volume"
|
"failed to find first volume"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -88,15 +90,15 @@ mod platform {
|
||||||
loop {
|
loop {
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = mem::uninitialized();
|
let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = mem::uninitialized();
|
||||||
if kernel32::FindNextVolumeW(
|
if winapi::um::fileapi::FindNextVolumeW(
|
||||||
next_volume_handle,
|
next_volume_handle,
|
||||||
name.as_mut_ptr(),
|
name.as_mut_ptr(),
|
||||||
name.len() as minwindef::DWORD,
|
name.len() as minwindef::DWORD,
|
||||||
) == 0
|
) == 0
|
||||||
{
|
{
|
||||||
match kernel32::GetLastError() {
|
match winapi::um::errhandlingapi::GetLastError() {
|
||||||
winerror::ERROR_NO_MORE_FILES => {
|
winerror::ERROR_NO_MORE_FILES => {
|
||||||
kernel32::FindVolumeClose(next_volume_handle);
|
winapi::um::fileapi::FindVolumeClose(next_volume_handle);
|
||||||
return volumes;
|
return volumes;
|
||||||
}
|
}
|
||||||
err => crash!(err as i32, "failed to find next volume"),
|
err => crash!(err as i32, "failed to find next volume"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue