Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(fs/windows): stat - only open file once #27487

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions ext/fs/std_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl FileSystem for RealFs {
umask(Mode::from_bits_truncate(mask as mode_t))
} else {
// If no mask provided, we query the current. Requires two syscalls.
let prev = umask(Mode::from_bits_truncate(0o777));
let prev = umask(Mode::from_bits_truncate(0));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let _ = umask(prev);
prev
};
Expand Down Expand Up @@ -802,6 +802,17 @@ fn stat_extra(
use winapi::um::winnt::FILE_SHARE_READ;
use winapi::um::winnt::FILE_SHARE_WRITE;

struct WinHandle(winapi::shared::ntdef::HANDLE);

impl Drop for WinHandle {
fn drop(&mut self) {
// SAFETY: winapi call
unsafe {
CloseHandle(self.0);
}
}
}

unsafe fn get_dev(
handle: winapi::shared::ntdef::HANDLE,
) -> std::io::Result<u64> {
Expand Down Expand Up @@ -883,11 +894,11 @@ fn stat_extra(
if file_handle == INVALID_HANDLE_VALUE {
return Err(std::io::Error::last_os_error().into());
}
let file_handle = WinHandle(file_handle);

let result = get_dev(file_handle);
fsstat.dev = result?;
fsstat.dev = get_dev(file_handle.0)?;

if let Ok(file_info) = query_file_information(file_handle) {
if let Ok(file_info) = query_file_information(file_handle.0) {
fsstat.ctime = Some(windows_time_to_unix_time_msec(
&file_info.BasicInformation.ChangeTime,
) as u64);
Expand Down Expand Up @@ -924,7 +935,6 @@ fn stat_extra(
}
}

CloseHandle(file_handle);
Ok(())
}
}
Expand Down
Loading