{"id":"62f7c086ab03e878","repo":"BurntSushi/ripgrep","slug":"walkdir-same-file-system-option-not-supported-on","errorCode":null,"errorMessage":"walkdir: same_file_system option not supported on this platform","messagePattern":"walkdir: same_file_system option not supported on this platform","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ignore/src/walk.rs","lineNumber":2187,"sourceCode":"\n#[cfg(unix)]\nfn device_num<P: AsRef<Path>>(path: P) -> io::Result<u64> {\n    use std::os::unix::fs::MetadataExt;\n\n    path.as_ref().metadata().map(|md| md.dev())\n}\n\n#[cfg(windows)]\nfn device_num<P: AsRef<Path>>(path: P) -> io::Result<u64> {\n    use winapi_util::{Handle, file};\n\n    let h = Handle::from_path_any(path)?;\n    file::information(h).map(|info| info.volume_serial_number())\n}\n\n#[cfg(not(any(unix, windows)))]\nfn device_num<P: AsRef<Path>>(_: P) -> io::Result<u64> {\n    Err(io::Error::new(\n        io::ErrorKind::Other,\n        \"walkdir: same_file_system option not supported on this platform\",\n    ))\n}\n\n#[cfg(test)]\nmod tests {\n    use std::ffi::OsStr;\n    use std::fs::{self, File};\n    use std::io::Write;\n    use std::path::Path;\n    use std::sync::{Arc, Mutex};\n\n    use super::{DirEntry, WalkBuilder, WalkState};\n    use crate::tests::TempDir;\n\n    fn wfile<P: AsRef<Path>>(path: P, contents: &str) {\n        let mut file = File::create(path).unwrap();","sourceCodeStart":2169,"sourceCodeEnd":2205,"githubUrl":"https://github.com/BurntSushi/ripgrep/blob/3fce3b5bb0236da2df6d99672afb8a719642eca7/crates/ignore/src/walk.rs#L2169-L2205","documentation":"device_num is implemented for unix (via MetadataExt::dev) and windows (via winapi_util volume serial number). The #[cfg(not(any(unix, windows)))] stub returns Err('walkdir: same_file_system option not supported on this platform'). It is hit when same_file_system traversal is enabled on a target with no device-number concept.","triggerScenarios":"Enabling WalkBuilder::same_file_system(true) (or the equivalent flag) on a non-unix/non-windows target; the walk attempts device_num to enforce the same-device constraint and gets this error.","commonSituations":"Cross-compiling ripgrep/ignore tooling to wasm32 with --files-with-matches and same_file_system enabled by config; a default config that turns on same_file_system unconditionally on a target that cannot support it.","solutions":["Disable same_file_system on the unsupported target (do not call WalkBuilder::same_file_system(true)).","Target a supported platform (unix or windows) if you need same-device traversal semantics.","Detect the target at build time and gate the same_file_system option behind cfg(any(unix, windows))."],"exampleFix":"// before\nlet mut wb = WalkBuilder::new(root);\nwb.same_file_system(true); // errors on wasm\n\n// after\nlet mut wb = WalkBuilder::new(root);\n#[cfg(any(unix, windows))]\nwb.same_file_system(true);","handlingStrategy":"validation","validationCode":"const SAME_FS_SUPPORTED: bool = cfg!(any(unix, windows));\n// only set same_file_system when true:\n// #[cfg(any(unix, windows))] wb.same_file_system(true);","typeGuard":null,"tryCatchPattern":"if cfg!(not(any(unix, windows))) {\n    eprintln!(\"same_file_system not supported here\");\n    return;\n}","preventionTips":["Do not enable same_file_system on non-unix/non-windows targets.","Gate the option behind cfg(any(unix, windows)).","Document platform limits for same-device traversal in your tool's docs."],"tags":["walk","platform","same-file-system","ignore"],"analyzedSha":"3fce3b5bb0236da2df6d99672afb8a719642eca7","analyzedAt":"2026-08-06T01:39:05.073Z","schemaVersion":2}