Skip to content

Commit b36dd8b

Browse files
committed
add sequential file access hint on windows
1 parent 60d5886 commit b36dd8b

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/tsort/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ thiserror = { workspace = true }
2525
uucore = { workspace = true }
2626
rustc-hash = { workspace = true }
2727

28+
[target.'cfg(windows)'.dependencies]
29+
windows-sys = { workspace = true, features = ["Win32_Storage_FileSystem"] }
30+
2831
[target.'cfg(unix)'.dependencies]
2932
rustix = { workspace = true, features = ["fs"] }
3033

src/uu/tsort/src/tsort.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
5757
if input == "-" {
5858
process_input(io::stdin().lock(), &mut g)?;
5959
} else {
60+
let mut options;
6061
// some platforms cannot catch this as read error. Needs additional cost by stat
6162
#[cfg(windows)]
6263
{
@@ -66,9 +67,23 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
6667
Error::Read(ReadError::IsDir(input.to_string_lossy().to_string())).into(),
6768
);
6869
}
70+
// advise the OS we will access the data sequentially if possible (windows)
71+
72+
use std::os::windows::fs::OpenOptionsExt;
73+
use windows_sys::Win32::Storage::FileSystem::FILE_FLAG_SEQUENTIAL_SCAN;
74+
options = File::options().custom_flags(FILE_FLAG_SEQUENTIAL_SCAN);
6975
}
70-
let file = File::open(input).map_err_context(|| input.maybe_quote().to_string())?;
71-
// advise the OS we will access the data sequentially if possible
76+
77+
#[cfg(not(windows))]
78+
{
79+
options = File::options();
80+
}
81+
let file = options
82+
.read(true)
83+
.open(input)
84+
.map_err_context(|| input.maybe_quote().to_string())?;
85+
86+
// advise the OS we will access the data sequentially if possible (unix)
7287
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
7388
let _ = rustix::fs::fadvise(&file, 0, None, rustix::fs::Advice::Sequential);
7489

0 commit comments

Comments
 (0)