storage-fault-probe.dhover×185all
#!/usr/bin/env dub
/+ dub.sdl:
    name "recovery-storage-fault-probe"
    targetPath "../../../build"
    dependency "sparkles:base" path="../../.."
    dependency "sparkles:event-horizon-sys" path="../../.."
    dependency "sparkles:recovery" path="../../.."
    dependency "sparkles:test-utils" path="../../.."
    dflags "-preview=in" "-preview=dip1000"
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
+/
/// A child process for strace syscall-fault injection; asserts forbidden destination writes.
module 
(module) storage_fault_probe

A child process for strace syscall-fault injection; asserts forbidden destination writes.

storage_fault_probe
;
import
(package) std
std
.
(package) std.algorithm
algorithm
.
(module) std.algorithm.searching

This is a submodule of std.algorithm. It contains generic searching algorithms.

Function Name Description
all all!"a > 0"([1, 2, 3, 4]) returns true because all elements are positive
any any!"a > 0"([1, 2, -3, -4]) returns true because at least one element is positive
balancedParens balancedParens("((1 + 1) / 2)", '(', ')') returns true because the string has balanced parentheses.
boyerMooreFinder find("hello world", boyerMooreFinder("or")) returns "orld" using the Boyer-Moore algorithm.
canFind canFind("hello world", "or") returns true.
count Counts all elements or elements matching a predicate, specific element or sub-range.

count([1, 2, 1]) returns 3, count([1, 2, 1], 1) returns 2 and count!"a < 0"([1, -3, 0]) returns 1. | | countUntil | countUntil(a, b) returns the number of steps taken in a to reach b; for example, countUntil("hello!", "o") returns 4. | | commonPrefix | commonPrefix("parakeet", "parachute") returns "para". | | endsWith | endsWith("rocks", "ks") returns true. | | extrema | extrema([2, 1, 3, 5, 4]) returns [1, 5]. | | find | find("hello world", "or") returns "orld" using linear search. (For binary search refer to SortedRange.) | | findAdjacent | findAdjacent([1, 2, 3, 3, 4]) returns the subrange starting with two equal adjacent elements, i.e. [3, 3, 4]. | | findAmong | findAmong("abcd", "qcx") returns "cd" because 'c' is among "qcx". | | findSkip | If a = "abcde", then findSkip(a, "x") returns false and leaves a unchanged, whereas findSkip(a, "c") advances a to "de" and returns true. | | findSplit | findSplit("abcdefg", "de") returns a tuple of three ranges "abc", "de", and "fg". | | findSplitAfter | findSplitAfter("abcdefg", "de") returns a tuple of two ranges "abcde" and "fg". | | findSplitBefore | findSplitBefore("abcdefg", "de") returns a tuple of two ranges "abc" and "defg". | | minCount | minCount([2, 1, 1, 4, 1]) returns tuple(1, 3). | | maxCount | maxCount([2, 4, 1, 4, 1]) returns tuple(4, 2). | | minElement | Selects the minimal element of a range. minElement([3, 4, 1, 2]) returns 1. | | maxElement | Selects the maximal element of a range. maxElement([3, 4, 1, 2]) returns 4. | | minIndex | Index of the minimal element of a range. minIndex([3, 4, 1, 2]) returns 2. | | maxIndex | Index of the maximal element of a range. maxIndex([3, 4, 1, 2]) returns 1. | | minPos | minPos([2, 3, 1, 3, 4, 1]) returns the subrange [1, 3, 4, 1], i.e., positions the range at the first occurrence of its minimal element. | | maxPos | maxPos([2, 3, 1, 3, 4, 1]) returns the subrange [4, 1], i.e., positions the range at the first occurrence of its maximal element. | | skipOver | Assume a = "blah". Then skipOver(a, "bi") leaves a unchanged and returns false, whereas skipOver(a, "bl") advances a to refer to "ah" and returns true. | | startsWith | startsWith("hello, world", "hello") returns true. | | until | Lazily iterates a range until a specific value is found. |

Source

std/algorithm/searching.d

@copyrightAndrei Alexandrescu 2008-.@licenseBoost License 1.0.@authorsAndrei Alexandrescu
searching
:
(alias template) storage_fault_probe.startsWith = std.algorithm.searching.startsWith(alias pred = (a, b) => a == b, Range, Needles...)(Range doesThisStart, Needles withOneOfThese) if (isInputRange!Range && (Needles.length > 1) && allSatisfy!(canTestStartsWith!(pred, Range), Needles))

Checks whether the given input range starts with (one of) the given needle(s) or, if no needles are given, if its front element fulfils predicate pred.

For more information about pred see find.

@parampred Predicate to use in comparing the elements of the haystack and the needle(s). Mandatory if no needles are given.@paramdoesThisStart The input range to check.@paramwithOneOfThese The needles against which the range is to be checked, which may be individual elements or input ranges of elements.@paramwithThis The single needle to check, which may be either a single element or an input range of elements.@returns

0 if the needle(s) do not occur at the beginning of the given range; otherwise the position of the matching needle, that is, 1 if the range starts with withOneOfThese[0], 2 if it starts with withOneOfThese[1], and so on.

In the case where doesThisStart starts with multiple of the ranges or elements in withOneOfThese, then the shortest one matches (if there are two which match which are of the same length (e.g. "a" and 'a'), then the left-most of them in the argument list matches).

In the case when no needle parameters are given, return true iff front of doesThisStart fulfils predicate pred.

startsWith
;
import
(package) std
std
.
(module) std.file

Utilities for manipulating files and scanning directories. Functions in this module handle files as a unit, e.g., read or write one file at a time. For opening files and manipulating them via handles refer to module std.stdio.

Category Functions
General exists isDir isFile isSymlink rename thisExePath
Directories chdir dirEntries getcwd mkdir mkdirRecurse rmdir rmdirRecurse tempDir
Files append copy read readText remove slurp write
Symlinks symlink readLink
Attributes attrIsDir attrIsFile attrIsSymlink getAttributes getLinkAttributes getSize setAttributes
Timestamp getTimes getTimesWin setTimes timeLastModified timeLastAccessed timeStatusChanged
Other DirEntry FileException PreserveAttributes SpanMode getAvailableDiskSpace

Source

std/file.d

@copyrightCopyright The D Language Foundation 2007 - 2011.@seeThe official tutorial for an introduction to working with files in D, module std.stdio for opening files and manipulating them via handles, and module std.path for manipulating path strings.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Jonathan M Davis
file
:
(alias template) storage_fault_probe.exists = std.file.exists(R)(R name) if (isSomeFiniteCharInputRange!R && !isConvertibleToString!R)

Determine whether the given file (or directory) exists.

@paramname string or range of characters representing the file name@returnstrue if the file name specified as input exists
exists
,
(alias template) storage_fault_probe.readText = std.file.readText(S = string, R)(auto ref R name) if (isSomeString!S && (isSomeFiniteCharInputRange!R || is(StringTypeOf!R)))

Reads and validates (using validate) a text file. S can be an array of any character type. However, no width or endian conversions are performed. So, if the width or endianness of the characters in the given file differ from the width or endianness of the element type of S, then validation will fail.

@paramS the string type of the file@paramname string or range of characters representing the file name@returnsArray of characters read.@throwsFileException if there is an error reading the file, UTFException on UTF decoding error.@seeread for reading a binary file.
readText
;
import
(package) std
std
.
(module) std.path

This module is used to manipulate path strings.

All functions, with the exception of expandTilde (and in some cases absolutePath and relativePath), are pure string manipulation functions; they don't depend on any state outside the program, nor do they perform any actual file system actions. This has the consequence that the module does not make any distinction between a path that points to a directory and a path that points to a file, and it does not know whether or not the object pointed to by the path actually exists in the file system. To differentiate between these cases, use isDir and exists.

Note that on Windows, both the backslash (\) and the slash (/) are in principle valid directory separators. This module treats them both on equal footing, but in cases where a new separator is added, a backslash will be used. Furthermore, the buildNormalizedPath function will replace all slashes with backslashes on that platform.

In general, the functions in this module assume that the input paths are well-formed. (That is, they should not contain invalid characters, they should follow the file system's path format, etc.) The result of calling a function on an ill-formed path is undefined. When there is a chance that a path or a file name is invalid (for instance, when it has been input by the user), it may sometimes be desirable to use the isValidFilename and isValidPath functions to check this.

Most functions do not perform any memory allocations, and if a string is returned, it is usually a slice of an input string. If a function allocates, this is explicitly mentioned in the documentation.

Category Functions
Normalization absolutePath asAbsolutePath asNormalizedPath asRelativePath buildNormalizedPath buildPath chainPath expandTilde
Partitioning baseName dirName dirSeparator driveName pathSeparator pathSplitter relativePath rootName stripDrive
Validation isAbsolute isDirSeparator isRooted isValidFilename isValidPath
Extension defaultExtension extension setExtension stripExtension withDefaultExtension withExtension
Other filenameCharCmp filenameCmp globMatch CaseSensitive

Source

std/path.d

@authorsLars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Khne, Andrei Alexandrescu@copyrightCopyright (c) 2000-2014, the authors. All rights reserved.@licenseBoost License 1.0
path
:
(alias template) storage_fault_probe.baseName = std.path.baseName(R)(return scope R path) if (isRandomAccessRange!R && hasSlicing!R && isSomeChar!(ElementType!R) && !isSomeString!R)

Note

This function only strips away the specified suffix, which doesn't necessarily have to represent an extension. To remove the extension from a path, regardless of what the extension is, use stripExtension. To obtain the filename without leading directories and without an extension, combine the functions like this:

assert(baseName(stripExtension("dir/file.ext")) == "file");
@paramcs Whether or not suffix matching is case-sensitive.@parampath A path name. It can be a string, or any random-access range of characters.@paramsuffix An optional suffix to be removed from the file name.@returns

The name of the file in the path name, without any leading directory and with an optional suffix chopped off.

If suffix is specified, it will be compared to path using filenameCmp!cs, where cs is an optional template parameter determining whether the comparison is case sensitive or not. See the filenameCmp documentation for details.

@standardsThis function complies with the POSIX requirements for the 'basename' shell utility (with suitable adaptations for Windows paths).
baseName
,
(alias template) storage_fault_probe.buildPath = std.path.buildPath(Range)(scope Range segments) if (isInputRange!Range && !isInfinite!Range && isSomeString!(ElementType!Range))

Combines one or more path segments.

This function takes a set of path segments, given as an input range of string elements or as a set of string arguments, and concatenates them with each other. Directory separators are inserted between segments if necessary. If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped.

On Windows, if one of the path segments are rooted, but not absolute (e.g. \foo), all preceding path segments down to the previous root will be dropped. (See below for an example.)

This function always allocates memory to hold the resulting path. The variadic overload is guaranteed to only perform a single allocation, as is the range version if paths is a forward range.

@paramsegments An input range of segments to assemble the path from.@returnsThe assembled path.
buildPath
,
(alias template) storage_fault_probe.dirName = std.path.dirName(R)(return scope R path) if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && isSomeChar!(ElementType!R) && !isSomeString!R)

Returns the parent directory of path. On Windows, this includes the drive letter if present. If path is a relative path and the parent directory is the current working directory, returns ".".

@parampath A path name.@returnsA slice of path or ".".@standardsThis function complies with the POSIX requirements for the 'dirname' shell utility (with suitable adaptations for Windows paths).
dirName
;
import
(package) std
std
.
(module) std.stdio
Category Symbols
File handles _popen File isFileHandle openNetwork stderr stdin stdout
Reading chunks lines readf readfln readln
Writing toFile write writef writefln writeln
Misc KeepTerminator LockType StdioException

Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio is publically imported when importing std.stdio.

There are three layers of I/O:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
stdio
:
(alias template) storage_fault_probe.writeln = std.stdio.writeln(T...)(T args)

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(module) sparkles.base.vfs

The capability VFS: a file-system interface over directory handles.

A program is given open directory handles instead of path strings and names every file relative to one of them, so code holding a handle cannot reach anything outside that directory, even while another process renames entries or plants symbolic links inside it. Each handle carries rights checked at compile time, which can be narrowed but never widened.

Specified in docs/specs/base/vfs/SPEC.md.

vfs
:
(enum) sparkles.base.vfs.types.AtomicDisposition

What writeFileAtomic does about an entry already at the name (VFO9).

AtomicDisposition
,
(struct) sparkles.base.vfs.types.AtomicMode

An atomic write's mode (VFO9). Like OpenMode, a template argument of writeFileAtomic, so the rights it needs are checked at compile time.

AtomicMode
,
(struct) sparkles.base.vfs.types.AtomicReceipt

What a committed atomic write reports beyond the commit itself (VFO9).

Examples

static assert(AtomicMode.replace.rights == (Rights.create | Rights.write | Rights.rename));
enum keeping = AtomicMode(AtomicDisposition.replace, keepPermissions: true);
static assert(hasRights(keeping.rights, Rights.stat));
AtomicReceipt
,
(alias template) storage_fault_probe.IoResult = sparkles.base.io.errors.IoResult(T)

The result of every I/O operation.

IoResult
,
(enum) sparkles.base.vfs.types.Rights

The operations a handle permits (VFH4). Rights are part of a handle's type, so an operation whose right is absent does not compile (VFH6), and a derived handle can only have fewer (VFH5).

Rights
,
(alias) storage_fault_probe.ambientAuthority = sparkles.base.vfs.handles.AmbientAuthority sparkles.base.vfs.handles.ambientAuthority() pure nothrow @nogc @safe

The token openRoot requires (VFH7). Only ``ambientAuthority() makes one, so searching for that name finds every place that creates authority from a path.

ambientAuthority
,
(alias template) storage_fault_probe.openRoot = sparkles.base.vfs.handles.openRoot(Rights R, V)(V* vfs, scope const(char)[] path, AmbientAuthority authority, ResolvePolicy policy = ResolvePolicy.init, CreateDefault create = CreateDefault.shared_, bool requireKernel = false) if (isVfs!V)

Opens the directory path as a root with rights R (VFH7). The only operation that resolves a path from the process root or current directory, and the only one that follows symbolic links in the path it is given.

openRoot
;
import
(package) sparkles
sparkles
.
(package) sparkles.event_horizon
event_horizon
.
(package) sparkles.event_horizon.sys
sys
.
(module) sparkles.event_horizon.sys.vfs

BlockingVfs: the capability VFS's blocking backend (VFB4), one blocking system call per primitive, relative to the parent handle.

On POSIX the primitives are the *at family, never following the named entry (VFN9). Directories a walk passes through are opened for search only where the platform can (VFN14). Linux resolves whole paths with openat2(2) and macOS with O_NOFOLLOW_ANY where the policy allows (VFN5); each probe's absence is cached for the process, its presence never (VFN3), and a race the kernel reports is retried up to the limit (VFN4).

Specified in docs/specs/base/vfs/backends.md.

vfs
:
(struct) sparkles.event_horizon.sys.vfs.BlockingVfs

The blocking backend over POSIX system calls.

BlockingVfs
;
import
(package) sparkles
sparkles
.
(package) sparkles.recovery
recovery
.
(module) sparkles.recovery.archive

Numbered immutable generation files in a recovery archive.

A generation is one opaque payload under a canonical name: 20 decimal digits and the layout's suffix (00000000000000000007.session). An append never replaces a file: it is a create-only atomic write through the capability VFS that syncs the directory (VFO9), so an earlier generation stays readable until a newer one is durably acknowledged. Reads accept only a regular file, never through a link (VFO12). Pruning keeps the newest valid generations at or below an acknowledged cutoff and leaves damaged, unsupported, linked and newer entries alone. A retirement marker records that a generation was adopted elsewhere without touching its bytes.

archive
:
(alias) storage_fault_probe.appendGeneration = sparkles.base.expected.Expected!(WriteReceipt, string, Abort) sparkles.recovery.archive.appendGeneration(string directory, ulong generation, scope const(char)[] bytes, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

Append bytes as generation, never replacing a file. The caller supplies an existing private directory whose creation is already durable, and retains earlier durable generations until this one is acknowledged durable.

appendGeneration
,
(alias) storage_fault_probe.readGeneration = sparkles.base.expected.Expected!(string, string, Abort) sparkles.recovery.archive.readGeneration(string directory, ulong generation, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

The payload of generation, read only from a regular file.

readGeneration
;
import
(package) sparkles
sparkles
.
(package) sparkles.test_utils
test_utils
.
(module) sparkles.test_utils.tmpfs
tmpfs
:
(struct) sparkles.test_utils.tmpfs.TmpFS

A scratch directory for a test, removed when the instance goes out of scope.

There are two ways to get one, and the difference is who owns the directory:

create makes a fresh, uniquely named directory and owns it: the whole tree — files written through this instance or behind its back, subdirectories, everything — is removed with the instance. This is what a test wants almost every time. share attaches to a directory that already exists and does not own it: only the files this instance wrote are removed, and the directory outlives it. This is for a test that deliberately has two fixtures over one tree, or one that must not delete what another made.

Ownership is decided by which constructor ran, never by what a later call happened to find on disk — so it cannot be forgotten, and a test that writes into dir() through the code under test rather than through this fixture still gets its tree cleaned up.

One instance is not thread-safe: writeFileAt appends to its file list and the destructor reads it. That is the intended shape — one fixture per test, used from the test's own thread — and create itself is safe to call concurrently. Sharing a single instance across threads needs the caller's own synchronization.

On POSIX, fixture writers are close-on-exec from the instant they open. An unrelated child executing concurrently cannot retain a writer after its exec and keep an executable fixture ETXTBSY after the parent's write has completed. This applies to both writeFile and writeFileAt.

Removal is best effort and never throws. A destructor that throws during unwinding replaces the assertion that actually failed with a cleanup error, and on Windows that is not hypothetical — git leaves read-only objects behind that make recursive removal fail.

TmpFS
;
/// A document save as an editor makes one: create-only, or replacing with the old mode.
(alias) sparkles.base.io.errors.IoResult!(sparkles.base.vfs.types.AtomicReceipt) = sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook)

The result of every I/O operation.

IoResult
!
(struct) sparkles.base.vfs.types.AtomicReceipt

What a committed atomic write reports beyond the commit itself (VFO9).

Examples

static assert(AtomicMode.replace.rights == (Rights.create | Rights.write | Rights.rename));
enum keeping = AtomicMode(AtomicDisposition.replace, keepPermissions: true);
static assert(hasRights(keeping.rights, Rights.stat));
AtomicReceipt
sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook) storage_fault_probe.save(string path, string bytes, bool creating) @system

A document save as an editor makes one: create-only, or replacing with the old mode.

save
(
(alias) object.string = string
string
(parameter) string path
path
,
(alias) object.string = string
string
(parameter) string bytes
bytes
, bool
(parameter) bool creating
creating
) @system
{ enum
(constant) sparkles.base.vfs.types.AtomicMode storage_fault_probe.save.create = AtomicMode(AtomicDisposition.createNew, false, true, false)
create
=
(struct) sparkles.base.vfs.types.AtomicMode

An atomic write's mode (VFO9). Like OpenMode, a template argument of writeFileAtomic, so the rights it needs are checked at compile time.

AtomicMode
(
(enum) sparkles.base.vfs.types.AtomicDisposition

What writeFileAtomic does about an entry already at the name (VFO9).

AtomicDisposition
.
(enum value) sparkles.base.vfs.types.AtomicDisposition.createNew = 1

fail with exists, also when the entry appears during the write

createNew
, syncDirectory: true);
enum
(constant) sparkles.base.vfs.types.AtomicMode storage_fault_probe.save.replace = AtomicMode(AtomicDisposition.replace, true, true, false)
replace
=
(struct) sparkles.base.vfs.types.AtomicMode

An atomic write's mode (VFO9). Like OpenMode, a template argument of writeFileAtomic, so the rights it needs are checked at compile time.

AtomicMode
(
(enum) sparkles.base.vfs.types.AtomicDisposition

What writeFileAtomic does about an entry already at the name (VFO9).

AtomicDisposition
.
(enum value) sparkles.base.vfs.types.AtomicDisposition.replace = cast(ubyte)0u

replace it

replace
, keepPermissions: true, syncDirectory: true);
auto
(local variable) sparkles.base.expected.Expected!(Dir!(BlockingVfs, Rights.all), IoError, NoGcHook) dir
dir
=
sparkles.base.expected.Expected!(Dir!(BlockingVfs, Rights.all), IoError, NoGcHook) sparkles.base.vfs.handles.openRoot!(Rights.all, sparkles.event_horizon.sys.vfs.BlockingVfs)(sparkles.event_horizon.sys.vfs.BlockingVfs* vfs, scope const(char)[] path, sparkles.base.vfs.handles.AmbientAuthority authority, sparkles.base.vfs.types.ResolvePolicy policy = ResolvePolicy(SymlinkPolicy.none, DotDotPolicy.reject, false), sparkles.base.vfs.types.CreateDefault create = CreateDefault.shared_, bool requireKernel = false) @nogc @safe

Opens the directory path as a root with rights R (VFH7). The only operation that resolves a path from the process root or current directory, and the only one that follows symbolic links in the path it is given.

openRoot
!(
(enum) sparkles.base.vfs.types.Rights

The operations a handle permits (VFH4). Rights are part of a handle's type, so an operation whose right is absent does not compile (VFH6), and a derived handle can only have fewer (VFH5).

Rights
.
(enum value) sparkles.base.vfs.types.Rights.all = cast(ushort)511u

every right

all
)(new
(struct) sparkles.event_horizon.sys.vfs.BlockingVfs

The blocking backend over POSIX system calls.

BlockingVfs
,
string std.path.dirName!(immutable(char))(return scope string path) pure nothrow @nogc @safe

Returns the parent directory of path. On Windows, this includes the drive letter if present. If path is a relative path and the parent directory is the current working directory, returns ".".

Examples

assert(dirName("") == ".");
assert(dirName("file"w) == ".");
assert(dirName("dir/"d) == ".");
assert(dirName("dir///") == ".");
assert(dirName("dir/file"w.dup) == "dir");
assert(dirName("dir///file"d.dup) == "dir");
assert(dirName("dir/subdir/") == "dir");
assert(dirName("/dir/file"w) == "/dir");
assert(dirName("/file"d) == "/");
assert(dirName("/") == "/");
assert(dirName("///") == "/");

version (Windows)
{
    assert(dirName(`dir\`) == `.`);
    assert(dirName(`dir\\\`) == `.`);
    assert(dirName(`dir\file`) == `dir`);
    assert(dirName(`dir\\\file`) == `dir`);
    assert(dirName(`dir\subdir\`) == `dir`);
    assert(dirName(`\dir\file`) == `\dir`);
    assert(dirName(`\file`) == `\`);
    assert(dirName(`\`) == `\`);
    assert(dirName(`\\\`) == `\`);
    assert(dirName(`d:`) == `d:`);
    assert(dirName(`d:file`) == `d:`);
    assert(dirName(`d:\`) == `d:\`);
    assert(dirName(`d:\file`) == `d:\`);
    assert(dirName(`d:\dir\file`) == `d:\dir`);
    assert(dirName(`\\server\share\dir\file`) == `\\server\share\dir`);
    assert(dirName(`\\server\share\file`) == `\\server\share`);
    assert(dirName(`\\server\share\`) == `\\server\share`);
    assert(dirName(`\\server\share`) == `\\server\share`);
}
@parampath A path name.@returnsA slice of path or ".".@standardsThis function complies with the POSIX requirements for the 'dirname' shell utility (with suitable adaptations for Windows paths).
dirName
(
(parameter) string path
path
),
sparkles.base.vfs.handles.AmbientAuthority sparkles.base.vfs.handles.ambientAuthority() pure nothrow @nogc @safe

The token openRoot requires (VFH7). Only ``ambientAuthority() makes one, so searching for that name finds every place that creates authority from a path.

ambientAuthority
());
assert(!
(local variable) sparkles.base.expected.Expected!(Dir!(BlockingVfs, Rights.all), IoError, NoGcHook) dir
dir
.
bool sparkles.base.expected.Expected!(sparkles.base.vfs.handles.Dir!(BlockingVfs, Rights.all), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
);
return
(parameter) bool creating
creating
?
(local variable) sparkles.base.expected.Expected!(Dir!(BlockingVfs, Rights.all), IoError, NoGcHook) dir
dir
.
inout(sparkles.base.vfs.handles.Dir!(BlockingVfs, Rights.all)) sparkles.base.expected.Expected!(sparkles.base.vfs.handles.Dir!(BlockingVfs, Rights.all), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
.
(constant) sparkles.base.vfs.types.AtomicMode storage_fault_probe.save.create = AtomicMode(AtomicDisposition.createNew, false, true, false)
writeFileAtomic
!create(
sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook) sparkles.base.vfs.handles.Dir!(sparkles.event_horizon.sys.vfs.BlockingVfs, Rights.all).DirOperations!(sparkles.event_horizon.sys.vfs.BlockingVfs, Rights.all).writeFileAtomic!(AtomicMode(AtomicDisposition.createNew, false, true, false))(scope const(char)[] name, scope const(char)[] text) nothrow @nogc scope @safe

ditto, from text.

baseName
(
sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook) sparkles.base.vfs.handles.Dir!(sparkles.event_horizon.sys.vfs.BlockingVfs, Rights.all).DirOperations!(sparkles.event_horizon.sys.vfs.BlockingVfs, Rights.all).writeFileAtomic!(AtomicMode(AtomicDisposition.createNew, false, true, false))(scope const(char)[] name, scope const(char)[] text) nothrow @nogc scope @safe

ditto, from text.

path
),
(parameter) string bytes
bytes
)
:
(local variable) sparkles.base.expected.Expected!(Dir!(BlockingVfs, Rights.all), IoError, NoGcHook) dir
dir
.
inout(sparkles.base.vfs.handles.Dir!(BlockingVfs, Rights.all)) sparkles.base.expected.Expected!(sparkles.base.vfs.handles.Dir!(BlockingVfs, Rights.all), sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
.
(constant) sparkles.base.vfs.types.AtomicMode storage_fault_probe.save.replace = AtomicMode(AtomicDisposition.replace, true, true, false)
writeFileAtomic
!replace(
sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook) sparkles.base.vfs.handles.Dir!(sparkles.event_horizon.sys.vfs.BlockingVfs, Rights.all).DirOperations!(sparkles.event_horizon.sys.vfs.BlockingVfs, Rights.all).writeFileAtomic!(AtomicMode(AtomicDisposition.replace, true, true, false))(scope const(char)[] name, scope const(char)[] text) nothrow @nogc scope @safe

ditto, from text.

baseName
(
sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook) sparkles.base.vfs.handles.Dir!(sparkles.event_horizon.sys.vfs.BlockingVfs, Rights.all).DirOperations!(sparkles.event_horizon.sys.vfs.BlockingVfs, Rights.all).writeFileAtomic!(AtomicMode(AtomicDisposition.replace, true, true, false))(scope const(char)[] name, scope const(char)[] text) nothrow @nogc scope @safe

ditto, from text.

path
),
(parameter) string bytes
bytes
);
} private void
void storage_fault_probe.recoveryFault(string mode, ref sparkles.test_utils.tmpfs.TmpFS fixture) @system
recoveryFault
(
(alias) object.string = string
string
(parameter) string mode
mode
, ref
(struct) sparkles.test_utils.tmpfs.TmpFS

A scratch directory for a test, removed when the instance goes out of scope.

There are two ways to get one, and the difference is who owns the directory:

create makes a fresh, uniquely named directory and owns it: the whole tree — files written through this instance or behind its back, subdirectories, everything — is removed with the instance. This is what a test wants almost every time. share attaches to a directory that already exists and does not own it: only the files this instance wrote are removed, and the directory outlives it. This is for a test that deliberately has two fixtures over one tree, or one that must not delete what another made.

Ownership is decided by which constructor ran, never by what a later call happened to find on disk — so it cannot be forgotten, and a test that writes into dir() through the code under test rather than through this fixture still gets its tree cleaned up.

One instance is not thread-safe: writeFileAt appends to its file list and the destructor reads it. That is the intended shape — one fixture per test, used from the test's own thread — and create itself is safe to call concurrently. Sharing a single instance across threads needs the caller's own synchronization.

On POSIX, fixture writers are close-on-exec from the instant they open. An unrelated child executing concurrently cannot retain a writer after its exec and keep an executable fixture ETXTBSY after the parent's write has completed. This applies to both writeFile and writeFileAt.

Removal is best effort and never throws. A destructor that throws during unwinding replaces the assertion that actually failed with a cleanup error, and on Windows that is not hypothetical — git leaves read-only objects behind that make recursive removal fail.

TmpFS
(parameter) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
) @system
{ const
(local variable) const(string) source
source
=
(parameter) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
.
string sparkles.test_utils.tmpfs.TmpFS.writeFile(string contents, uint suffix = 0u) @safe
writeFile
("original bytes");
const
(local variable) const(sparkles.base.expected.Expected!(WriteReceipt, string, Abort)) first
first
=
sparkles.base.expected.Expected!(WriteReceipt, string, Abort) sparkles.recovery.archive.appendGeneration(string directory, ulong generation, scope const(char)[] bytes, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

Append bytes as generation, never replacing a file. The caller supplies an existing private directory whose creation is already durable, and retains earlier durable generations until this one is acknowledged durable.

appendGeneration
(
(parameter) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
.
string sparkles.test_utils.tmpfs.TmpFS.dir() const pure nothrow @nogc @safe

The scratch directory's path. It exists for as long as the instance does (and, for share, for as long as its real owner keeps it).

dir
, 1, "old unsaved");
assert(
(local variable) const(sparkles.base.expected.Expected!(WriteReceipt, string, Abort)) first
first
.
bool sparkles.base.expected.Expected!(sparkles.recovery.archive.WriteReceipt, string, sparkles.base.expected.Abort).hasValue!()() const pure nothrow @nogc @property @safe

Checks if Expected has value

hasValue
&&
(local variable) const(sparkles.base.expected.Expected!(WriteReceipt, string, Abort)) first
first
.
inout(sparkles.recovery.archive.WriteReceipt) sparkles.base.expected.Expected!(sparkles.recovery.archive.WriteReceipt, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
.
(field) bool sparkles.recovery.archive.WriteReceipt.durable

the directory sync after the commit succeeded

durable
);
const
(local variable) const(sparkles.base.expected.Expected!(WriteReceipt, string, Abort)) second
second
=
sparkles.base.expected.Expected!(WriteReceipt, string, Abort) sparkles.recovery.archive.appendGeneration(string directory, ulong generation, scope const(char)[] bytes, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

Append bytes as generation, never replacing a file. The caller supplies an existing private directory whose creation is already durable, and retains earlier durable generations until this one is acknowledged durable.

appendGeneration
(
(parameter) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
.
string sparkles.test_utils.tmpfs.TmpFS.dir() const pure nothrow @nogc @safe

The scratch directory's path. It exists for as long as the instance does (and, for share, for as long as its real owner keeps it).

dir
, 2, "new unsaved");
if (
(parameter) string mode
mode
== "recovery-directory-sync-failure")
{ assert(
(local variable) const(sparkles.base.expected.Expected!(WriteReceipt, string, Abort)) second
second
.
bool sparkles.base.expected.Expected!(sparkles.recovery.archive.WriteReceipt, string, sparkles.base.expected.Abort).hasValue!()() const pure nothrow @nogc @property @safe

Checks if Expected has value

hasValue
&& !
(local variable) const(sparkles.base.expected.Expected!(WriteReceipt, string, Abort)) second
second
.
inout(sparkles.recovery.archive.WriteReceipt) sparkles.base.expected.Expected!(sparkles.recovery.archive.WriteReceipt, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
.
(field) bool sparkles.recovery.archive.WriteReceipt.durable

the directory sync after the commit succeeded

durable
&&
(local variable) const(sparkles.base.expected.Expected!(WriteReceipt, string, Abort)) second
second
.
inout(sparkles.recovery.archive.WriteReceipt) sparkles.base.expected.Expected!(sparkles.recovery.archive.WriteReceipt, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
.
(field) string sparkles.recovery.archive.WriteReceipt.warning

what the caller should tell its user, if anything

warning
.
(field) ulong const(string).length
length
);
assert(
sparkles.base.expected.Expected!(string, string, Abort) sparkles.recovery.archive.readGeneration(string directory, ulong generation, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

The payload of generation, read only from a regular file.

readGeneration
(
(parameter) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
.
string sparkles.test_utils.tmpfs.TmpFS.dir() const pure nothrow @nogc @safe

The scratch directory's path. It exists for as long as the instance does (and, for share, for as long as its real owner keeps it).

dir
, 2).
inout(string) sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
== "new unsaved");
} else { assert(
(parameter) string mode
mode
== "recovery-precommit" &&
(local variable) const(sparkles.base.expected.Expected!(WriteReceipt, string, Abort)) second
second
.
bool sparkles.base.expected.Expected!(sparkles.recovery.archive.WriteReceipt, string, sparkles.base.expected.Abort).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
);
assert(
sparkles.base.expected.Expected!(string, string, Abort) sparkles.recovery.archive.readGeneration(string directory, ulong generation, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

The payload of generation, read only from a regular file.

readGeneration
(
(parameter) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
.
string sparkles.test_utils.tmpfs.TmpFS.dir() const pure nothrow @nogc @safe

The scratch directory's path. It exists for as long as the instance does (and, for share, for as long as its real owner keeps it).

dir
, 2).
bool sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
);
} assert(
sparkles.base.expected.Expected!(string, string, Abort) sparkles.recovery.archive.readGeneration(string directory, ulong generation, in sparkles.recovery.archive.ArchiveLayout layout = ArchiveLayout(".generation", "retired-", "SPARKLES-RECOVERY-RETIRED/1", 536870912LU)) nothrow @safe

The payload of generation, read only from a regular file.

readGeneration
(
(parameter) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
.
string sparkles.test_utils.tmpfs.TmpFS.dir() const pure nothrow @nogc @safe

The scratch directory's path. It exists for as long as the instance does (and, for share, for as long as its real owner keeps it).

dir
, 1).
inout(string) sparkles.base.expected.Expected!(string, string, sparkles.base.expected.Abort).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
== "old unsaved");
assert(
string std.file.readText!(string, const(string))(ref const(string) name) @safe

Reads and validates (using validate) a text file. S can be an array of any character type. However, no width or endian conversions are performed. So, if the width or endianness of the characters in the given file differ from the width or endianness of the element type of S, then validation will fail.

Examples

Read file with UTF-8 text.

write(deleteme, "abc"); // deleteme is the name of a temporary file
scope(exit) remove(deleteme);
string content = readText(deleteme);
assert(content == "abc");
@paramS the string type of the file@paramname string or range of characters representing the file name@returnsArray of characters read.@throwsFileException if there is an error reading the file, UTFException on UTF decoding error.@seeread for reading a binary file.
readText
(
(local variable) const(string) source
source
) == "original bytes");
} int
int D main(string[] args) @system
main
(
(alias) object.string = string
string
[]
(parameter) string[] args
args
) @system
{ assert(
(parameter) string[] args
args
.
(field) ulong string[].length
length
== 2, "Pass a save or recovery fault mode.");
const
(local variable) const(string) mode
mode
=
(parameter) string[] args
args
[1];
auto
(local variable) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
=
(struct) sparkles.test_utils.tmpfs.TmpFS

A scratch directory for a test, removed when the instance goes out of scope.

There are two ways to get one, and the difference is who owns the directory:

create makes a fresh, uniquely named directory and owns it: the whole tree — files written through this instance or behind its back, subdirectories, everything — is removed with the instance. This is what a test wants almost every time. share attaches to a directory that already exists and does not own it: only the files this instance wrote are removed, and the directory outlives it. This is for a test that deliberately has two fixtures over one tree, or one that must not delete what another made.

Ownership is decided by which constructor ran, never by what a later call happened to find on disk — so it cannot be forgotten, and a test that writes into dir() through the code under test rather than through this fixture still gets its tree cleaned up.

One instance is not thread-safe: writeFileAt appends to its file list and the destructor reads it. That is the intended shape — one fixture per test, used from the test's own thread — and create itself is safe to call concurrently. Sharing a single instance across threads needs the caller's own synchronization.

On POSIX, fixture writers are close-on-exec from the instant they open. An unrelated child executing concurrently cannot retain a writer after its exec and keep an executable fixture ETXTBSY after the parent's write has completed. This applies to both writeFile and writeFileAt.

Removal is best effort and never throws. A destructor that throws during unwinding replaces the assertion that actually failed with a cleanup error, and on Windows that is not hypothetical — git leaves read-only objects behind that make recursive removal fail.

TmpFS
.
sparkles.test_utils.tmpfs.TmpFS sparkles.test_utils.tmpfs.TmpFS.create(string prefix = __FUNCTION__, string basePath = tempDir()) @safe

Creates a fresh scratch directory and returns the fixture that owns it.

prefix names the fixture for a human reading /tmp; it does not have to be unique. The directory actually used appends a random token and a process-wide ordinal, which makes three problems impossible rather than merely unlikely:

Two concurrent runs of one suite — two worktrees, two agents, a CI matrix sharing a runner — cannot share a directory and delete each other's fixtures mid-test. A crashed run cannot leave a directory behind for the next run to inherit and read a previous run's files from. The token is random rather than the process id for exactly this case: pids are recycled, so ``prefix-<pid>-1 recurs and would collide with the leftovers of a run that died holding the same pid. Two fixtures in one test function cannot collide, so neither needs an artificial prefix to tell them apart.

The directory exists when this returns, so a test may hand dir() to the code under test immediately; whatever that code puts there is removed with the fixture.

prefix defaults to the calling function. That is a good name when the call sits in the test; from a shared helper it names the helper, which is merely less informative — no longer a correctness problem.

create
();
if (
(local variable) const(string) mode
mode
.
bool std.algorithm.searching.startsWith!("a == b", string, string)(string doesThisStart, string withThis) pure nothrow @nogc @safe

Checks whether the given input range starts with (one of) the given needle(s) or, if no needles are given, if its front element fulfils predicate pred.

For more information about pred see find.

@parampred Predicate to use in comparing the elements of the haystack and the needle(s). Mandatory if no needles are given.@paramdoesThisStart The input range to check.@paramwithOneOfThese The needles against which the range is to be checked, which may be individual elements or input ranges of elements.@paramwithThis The single needle to check, which may be either a single element or an input range of elements.@returns

0 if the needle(s) do not occur at the beginning of the given range; otherwise the position of the matching needle, that is, 1 if the range starts with withOneOfThese[0], 2 if it starts with withOneOfThese[1], and so on.

In the case where doesThisStart starts with multiple of the ranges or elements in withOneOfThese, then the shortest one matches (if there are two which match which are of the same length (e.g. "a" and 'a'), then the left-most of them in the argument list matches).

In the case when no needle parameters are given, return true iff front of doesThisStart fulfils predicate pred.

startsWith
("recovery-"))
{
void storage_fault_probe.recoveryFault(string mode, ref sparkles.test_utils.tmpfs.TmpFS fixture) @system
recoveryFault
(
(local variable) const(string) mode
mode
,
(local variable) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
);
void std.stdio.writeln!(string, string)(string __param_0, string __param_1) @safe

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
(
(local variable) const(string) mode
mode
, ": verified");
return 0; } const
(local variable) const(bool) creating
creating
=
(local variable) const(string) mode
mode
== "create-failure";
const
(local variable) const(string) path
path
=
(local variable) const(bool) creating
creating
?
string std.path.buildPath!char(const(char)[][] paths...) pure nothrow @safe

Combines one or more path segments.

This function takes a set of path segments, given as an input range of string elements or as a set of string arguments, and concatenates them with each other. Directory separators are inserted between segments if necessary. If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped.

On Windows, if one of the path segments are rooted, but not absolute (e.g. \foo), all preceding path segments down to the previous root will be dropped. (See below for an example.)

This function always allocates memory to hold the resulting path. The variadic overload is guaranteed to only perform a single allocation, as is the range version if paths is a forward range.

Examples

version (Posix)
{
    assert(buildPath("foo", "bar", "baz") == "foo/bar/baz");
    assert(buildPath("/foo/", "bar/baz")  == "/foo/bar/baz");
    assert(buildPath("/foo", "/bar")      == "/bar");
}

version (Windows)
{
    assert(buildPath("foo", "bar", "baz") == `foo\bar\baz`);
    assert(buildPath(`c:\foo`, `bar\baz`) == `c:\foo\bar\baz`);
    assert(buildPath("foo", `d:\bar`)     == `d:\bar`);
    assert(buildPath("foo", `\bar`)       == `\bar`);
    assert(buildPath(`c:\foo`, `\bar`)    == `c:\bar`);
}
@paramsegments An input range of segments to assemble the path from.@returnsThe assembled path.
buildPath
(
(local variable) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
.
string sparkles.test_utils.tmpfs.TmpFS.dir() const pure nothrow @nogc @safe

The scratch directory's path. It exists for as long as the instance does (and, for share, for as long as its real owner keeps it).

dir
, "new.txt") :
(local variable) sparkles.test_utils.tmpfs.TmpFS fixture
fixture
.
string sparkles.test_utils.tmpfs.TmpFS.writeFile(string contents, uint suffix = 0u) @safe
writeFile
("original bytes");
const
(local variable) const(sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook)) result
result
=
sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook) storage_fault_probe.save(string path, string bytes, bool creating) @system

A document save as an editor makes one: create-only, or replacing with the old mode.

save
(
(local variable) const(string) path
path
, "replacement bytes",
(local variable) const(bool) creating
creating
);
if (
(local variable) const(string) mode
mode
== "baseline")
{ assert(!
(local variable) const(sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook)) result
result
.
bool sparkles.base.expected.Expected!(sparkles.base.vfs.types.AtomicReceipt, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
&&
(local variable) const(sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook)) result
result
.
inout(sparkles.base.vfs.types.AtomicReceipt) sparkles.base.expected.Expected!(sparkles.base.vfs.types.AtomicReceipt, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
.
(field) bool sparkles.base.vfs.types.AtomicReceipt.directorySynced

The directory was synced after the commit, so the new name survives a crash. False when the mode did not ask, or the sync failed.

directorySynced
);
assert(
string std.file.readText!(string, const(string))(ref const(string) name) @safe

Reads and validates (using validate) a text file. S can be an array of any character type. However, no width or endian conversions are performed. So, if the width or endianness of the characters in the given file differ from the width or endianness of the element type of S, then validation will fail.

Examples

Read file with UTF-8 text.

write(deleteme, "abc"); // deleteme is the name of a temporary file
scope(exit) remove(deleteme);
string content = readText(deleteme);
assert(content == "abc");
@paramS the string type of the file@paramname string or range of characters representing the file name@returnsArray of characters read.@throwsFileException if there is an error reading the file, UTFException on UTF decoding error.@seeread for reading a binary file.
readText
(
(local variable) const(string) path
path
) == "replacement bytes");
} else if (
(local variable) const(string) mode
mode
== "directory-sync-failure")
{ assert(!
(local variable) const(sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook)) result
result
.
bool sparkles.base.expected.Expected!(sparkles.base.vfs.types.AtomicReceipt, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
&& !
(local variable) const(sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook)) result
result
.
inout(sparkles.base.vfs.types.AtomicReceipt) sparkles.base.expected.Expected!(sparkles.base.vfs.types.AtomicReceipt, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).value!()() inout pure nothrow @nogc @property ref @safe

Returns the expected value if there is one.

With default Abort hook, it asserts when there is no value. It calls hook's onAccessEmptyValue otherwise.

It returns T.init when hook doesn't provide onAccessEmptyValue.

Note

Value is returned by reference only when hook provides onAccessEmptyValue. Otherwise the T.init fallback forces it to be returned by value (a copy).

value
.
(field) bool sparkles.base.vfs.types.AtomicReceipt.directorySynced

The directory was synced after the commit, so the new name survives a crash. False when the mode did not ask, or the sync failed.

directorySynced
);
assert(
string std.file.readText!(string, const(string))(ref const(string) name) @safe

Reads and validates (using validate) a text file. S can be an array of any character type. However, no width or endian conversions are performed. So, if the width or endianness of the characters in the given file differ from the width or endianness of the element type of S, then validation will fail.

Examples

Read file with UTF-8 text.

write(deleteme, "abc"); // deleteme is the name of a temporary file
scope(exit) remove(deleteme);
string content = readText(deleteme);
assert(content == "abc");
@paramS the string type of the file@paramname string or range of characters representing the file name@returnsArray of characters read.@throwsFileException if there is an error reading the file, UTFException on UTF decoding error.@seeread for reading a binary file.
readText
(
(local variable) const(string) path
path
) == "replacement bytes");
} else { assert(
(local variable) const(string) mode
mode
== "precommit" ||
(local variable) const(bool) creating
creating
);
assert(
(local variable) const(sparkles.base.expected.Expected!(AtomicReceipt, IoError, NoGcHook)) result
result
.
bool sparkles.base.expected.Expected!(sparkles.base.vfs.types.AtomicReceipt, sparkles.base.io.errors.IoError, sparkles.base.text.errors.NoGcHook).hasError!()() const pure nothrow @nogc @property @safe

Checks if Expected has error

hasError
, "The syscall fault did not reach the intended save stage.");
if (
(local variable) const(bool) creating
creating
) assert(!
bool std.file.exists!string(string name) nothrow @nogc @safe

Determine whether the given file (or directory) exists.

@paramname string or range of characters representing the file name@returnstrue if the file name specified as input exists
exists
(
(local variable) const(string) path
path
), "A failed atomic create wrote a destination.");
else assert(
string std.file.readText!(string, const(string))(ref const(string) name) @safe

Reads and validates (using validate) a text file. S can be an array of any character type. However, no width or endian conversions are performed. So, if the width or endianness of the characters in the given file differ from the width or endianness of the element type of S, then validation will fail.

Examples

Read file with UTF-8 text.

write(deleteme, "abc"); // deleteme is the name of a temporary file
scope(exit) remove(deleteme);
string content = readText(deleteme);
assert(content == "abc");
@paramS the string type of the file@paramname string or range of characters representing the file name@returnsArray of characters read.@throwsFileException if there is an error reading the file, UTFException on UTF decoding error.@seeread for reading a binary file.
readText
(
(local variable) const(string) path
path
) == "original bytes", "A failed save changed the destination.");
}
void std.stdio.writeln!(string, string)(string __param_0, string __param_1) @safe

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
(
(local variable) const(string) mode
mode
, ": verified");
return 0; }