Documentation
¶
Overview ¶
Package localname is the one rule for what a name becomes on the disk of the computer a file is written to: whether that operating system can hold it at all (Problem), what it is called there when it cannot (Safe, Alias, Numbered), and when two different names are ONE file there (Key).
filex keeps the name it is given (internal/leafname says which names a door accepts), so a server holds names a person's own computer cannot: `report.` (Windows drops the trailing dot), `CON` and `aux.txt` (device names), `a:b.txt` (a forbidden character), a 300-byte Chinese name (ext4 and APFS hold 255 bytes), and `Rapor.docx` beside `rapor.docx` (NTFS and APFS compare names without case, APFS also without the normalisation form). Every program that writes server names onto a local disk asks this package: the sync engine (internal/filesync, which writes such an item under its Alias and remembers the pairing), `filex decrypt` (internal/e2edecrypt, which renames and warns). The desktop app's drag-out applies the same rules in TypeScript (desktop/src/local-name.ts, tested against the same hostile names).
The operating system is a parameter, never runtime.GOOS read here, so the rules of all three are tested on the one the suite runs on.
Leaf package: it imports nothing from filex.
Index ¶
- Constants
- func Alias(name, goos string) string
- func Fit(name, goos string) string
- func Fold(name string) string
- func Folds(goos string) bool
- func Image(name, goos string) (image string, ok bool)
- func Key(name, goos string) string
- func Numbered(name string, n int, goos string) string
- func Problem(name, goos string) string
- func Safe(name, goos string) string
Constants ¶
const ( // Reserved: a Windows device name (CON, PRN, AUX, NUL, COM1-9, LPT1-9), // with or without an extension - `aux.txt` included, which Windows 10 // still opens as the device. Reserved = "reserved" // Forbidden: a character Windows refuses in a name - < > : " | ? * \ / // or a control character. Forbidden = "forbidden" // Trailing: the name ends in a dot or a space, which Windows removes, so // the file it writes has another name. Trailing = "trailing" // TooLong: over MaxLen - bytes of UTF-8 on Linux and macOS, UTF-16 // units on Windows. TooLong = "too_long" )
Why a name cannot exist on a computer, as a stable code.
const MaxLen = 255
MaxLen is the longest one name may be: 255 bytes of UTF-8 on ext4, XFS and APFS, 255 UTF-16 units on NTFS.
Variables ¶
This section is empty.
Functions ¶
func Alias ¶
Alias is the name a copy of a server item is written under on goos when its own name cannot be (Problem != ""): Safe, shortened to fit (Fit), and made safe again - a cut can leave a trailing space. A name goos holds comes back as it is.
func Fit ¶
Fit shortens a name to MaxLen for goos, taking whole characters off the end of its stem and keeping its extension (when the extension is a short one). A name that fits is returned as it is.
func Fold ¶
Fold compares names the way the strictest target does (case-insensitive and Unicode-normalised): a key for output that may land on any computer.
func Folds ¶
Folds reports whether goos's usual file system calls two different names one: case-insensitive NTFS, case- and normalisation-insensitive APFS.
func Image ¶
Image is the name goos actually writes when a program asks for name and does not check: Windows drops trailing dots and spaces (`report.` is written as `report`) and reads a backslash as a separator (`a\b.txt` is a folder `a`). ok is false when the name is written as it is, or when nothing recognisable is written at all.
func Key ¶
Key is the name as goos's file system compares it: two names with one Key are one file there. NTFS ignores case and keeps both normalisation forms apart; APFS ignores both; everything else compares the bytes.
func Numbered ¶
Numbered is name with " (n)" before its extension, shortened to fit: the next candidate when an Alias is already one name here with another item's.
Types ¶
This section is empty.