Skip to main content

prepare

Function prepare 

Source
pub fn prepare(path: &Wtf16Str) -> Result<PreparedPath, PathError>
Expand description

Validate and, where the contract calls for it, resolve a caller’s path.

The returned value is the exact path a worker will later open, subject to the session hazard PreparedPath documents.

§Errors

Returns PathError for an empty path, an interior NUL, a \?\ path that is not fully qualified, an ordinary path that exceeds MAX_PATH before or after resolution, or a resolution failure reported by Windows.

§Example

Each rejection names what was wrong, on the calling thread, rather than producing a path that fails later with a code that explains nothing:

use windows_namespace_request_sys::path::PathFailure;
use windows_namespace_request_sys::prepare;
use wtf_string::Wtf16String;

let empty = prepare(&Wtf16String::new()).expect_err("an empty path names nothing");
assert_eq!(empty.failure(), PathFailure::EmptyPath);

// A verbatim path that is not fully qualified cannot be repaired later,
// because Win32 will not parse it.
// A drive-RELATIVE verbatim path is refused: verbatim parsing would
// treat the whole thing as a literal name rather than the current
// directory on C:, and that cannot be repaired later.
let drive_relative = prepare(&Wtf16String::from(r"\\?\C:relative\path"))
    .expect_err("a drive-relative verbatim path is not fully qualified");
assert_eq!(drive_relative.failure(), PathFailure::NotFullyQualified);

// These are decided here, before any Win32 call, so they carry no OS code.
assert_eq!(empty.raw_os_error(), None);