FileSystem v0.1.0

Source
Files, directories and filesystem operations

Installation

Add FileSystem to the [Dependencies] table of your package's Rux.toml:

[Dependencies]
FileSystem = { Namespace = "Rux", Version = "0.1.0" }

Standard packages are declared by hand: the registry does not serve them, so rux add Rux/FileSystem cannot add them.

Dependencies

Guide

What it provides

  • File and OpenOptions — a move-only owned handle the type system closes exactly once and copyable options created with OpenOptions(). Safe operations borrow the handle through &File or &var File; only stored platform handles and explicit output slots remain raw pointers.
  • Deterministic owners — directory iterators, temporary files and directories, and atomic writes prohibit copying, transfer with <-, and clean up through ~Type destructors. Fallible operations such as Open, Create, and Begin keep their descriptive names.
  • A file is a stream, and a stream is usually a borrow — File implements Reader, Writer and Seeker, so anything wanting a stream for the length of a call takes the file:
    WriteAll(file, contents)?;
    

    The borrow is checked and ends at the call, which means the compiler also refuses reading the file through while a borrow of it is still live. FileStream is the stored form, for a value such as a BufferedReader that keeps its source past the call that made it — binding the file itself into an interface value there would move it, and there would be nothing left to close. Its representation is private and File::Stream is the only way to obtain one; it must not outlive the file or survive a move of it, and nothing tracks either. A stream over a closed file is not unsafe: the file checks its own handle, so every operation refuses with InvalidHandle. AtomicWrite is itself a Writer, so replacing a file needs no adapter at all.
  • Native error translation — every operation that can fail returns a native fallible whose failure is an Io::IoError: the kind a caller acts on, with the platform's raw code preserved beside it, translated by one table per platform rather than ad hoc at each call site. File::Open, ReadDirectory, MetadataOf, and the other constructors and queries succeed with their value, and the rest succeed with (); a directory iterator's Next succeeds with none at the end.

Index

Types

NameSummary
AtomicWriteA file being written to replace target, which appears under that name only when it is complete.
DirectoryIteratorA directory read one entry at a time.
OpenOptionsWhat an open may do, and what it does about existence.
FileAn owned, open file.
FileStreamA stored borrow of an open file that speaks the stream interfaces.
FileKindWhat kind of thing a name refers to.
PermissionsWho may do what to a file, in both spellings the supported systems use.
MetadataEverything a single query can say about a file.
CapabilitiesWhat the running system can actually answer, so a caller can ask before it assumes.
TemporaryFileA temporary file that owns both its contents and its name.
TemporaryDirectoryHandleA temporary directory that owns its name.

Functions

NameSummary
WriteAtomicallyReplaces target with contents, atomically.
MakeDirectoryCreates the directory path names.
DeleteDirectoryDeletes the empty directory path names; a directory with anything still in it is refused.
DeleteFileDeletes the file path names.
ReadDirectoryBegins enumerating the directory path names.
CurrentDirectoryThe process's working directory, as an absolute path.
SetCurrentDirectoryMakes path the process's working directory.
Absolutepath made absolute against the working directory and simplified lexically.
CanonicalizeThe one true name of the existing file path refers to.
CapabilitiesOfSystemWhat this system can answer.
MetadataOfDescribes the file path names.
SetPermissionsSets who may do what to the file path names.
SetTimesSets the access and modification times of the file path names.
TemporaryDirectoryThe directory the system sets aside for temporary files.
RenameRenames from to to, moving it between directories if the paths differ there.
CreateHardLinkCreates link as a hard link: a second name for the file existing names.
CreateSymbolicLinkCreates link as a symbolic link holding target as its text.
CopyFileCopies the file from names to to, following a symbolic link to the bytes it points at.
NativeKindThe meaning of a platform error code on the platform this program was compiled for.
TranslateNativeA platform error code as the structured error everything here reports.

Constants

NameSummary
SymbolicLinkLimitHow many symbolic links one canonicalization will follow before giving up.
TemporaryNameAttemptsHow many names are tried before a temporary file gives up.