Skip to main content

Module path

Module path 

Source
Expand description

NsPath: a validated namespace path, and the portable name grammar every backend enforces through it.

The grammar is one deliberately strict subset of what Linux, macOS and Windows each allow. The point is that a name accepted here is legal, unambiguous and round-trippable on every platform, so “it worked on my Linux box and then collided on the Mac” is refused at the namespace, not discovered at a backend. It is intentionally stricter than any single OS: the rules below are not “what the host would accept”.

A path is absolute (/a/b), /-separated, and the root is /. There is no relative form, no ./.., no //, no trailing /. A name is refused (never silently repaired) when it:

  • is empty, . or ..;
  • is not already in Unicode NFC (the namespace never normalises, because normalising silently changes which entry a caller addressed);
  • contains a control character (char::is_control, so C0, DEL and C1), a format character from the fixed list in is_format_character (bidirectional controls, zero-width spaces, the soft hyphen, the byte-order mark: all invisible or reordering characters), \, : or any of <>"|?*;
  • ends in a dot or a space (Windows strips them, so the name would not round-trip);
  • is a Windows reserved device name (CON PRN AUX NUL COM1-9 LPT1-9, plus CONIN$, CONOUT$ and the superscript digit forms), case-insensitively, with or without an extension (con.txt is as reserved as CON);
  • is longer than MAX_NAME_BYTES (255) UTF-8 bytes, or the whole path is longer than MAX_PATH_BYTES (4096);
  • begins with TEMP_PREFIX (compared case-folded, so .SKNS-TMP- on a case-insensitive volume is refused too), which HostDir reserves for its atomic-replace temporary files.

Why the format characters: a name is something a person reads (a confirmation diff of a launcher entry, a file manager, a log line). A name that can display as something other than what it is (a right-to-left override that reverses txt.exe into exe.txt, a zero-width space that makes two different names look identical) lets one entry impersonate another in front of the person deciding. The list is fixed, not a Unicode category lookup, so a Unicode update cannot silently change which names are legal. Zero-width joiner (U+200D) and non-joiner (U+200C) stay legal: scripts such as Persian, Devanagari and emoji sequences need them.

Two names that differ only by case (or only by Unicode normalisation form) are distinct paths but cannot coexist in one directory: creating the second is refused with CaseCollision (see case_fold_key), on every backend, even a case-sensitive one.

Structs§

NsPath
A validated namespace path: absolute, /-separated, every component inside the portable name grammar. See the module docs for the grammar.

Enums§

PathReason
Why a path or name was refused. Carried by NsErrorKind::InvalidPath.

Constants§

MAX_NAME_BYTES
Longest single path component, in UTF-8 bytes. Matches the limit of ext4, APFS, NTFS and most others.
MAX_PATH_BYTES
Longest whole path, in UTF-8 bytes, separators included.
TEMP_PREFIX
The prefix HostDir gives its temporary files while it does an atomic replace.

Functions§

case_fold_key
The key under which two names count as “the same name differing only by case or normalisation form”.
is_format_character
The characters the grammar refuses as format characters: a fixed list, deliberately not a Unicode category.
validate_name
Check one component against the portable grammar. This is the single validator: NsPath uses it, and a backend that reads names back from a host directory uses it to decide which entries are addressable at all.