Skip to content

Class DirectorySource

Namespace: Apogee.Content.FileSystem
Assembly: Apogee.Content.dll

A folder of the real file system. Paths are joined to the folder after they were checked to hold only plain names, and the result is checked to be inside it. A link inside the folder that points out of it is followed, as the operating system does: do not mount a folder whose contents you do not trust to be links-free.

A write is durable and whole: the bytes go to a hidden file of a unique name beside the target, are flushed to the disk, and the file is then renamed over the target, so a crash or a full disk leaves the old file, and not an empty one. A file that is a symbolic link is written through: the new bytes go to the file the link leads to, and the link stays a link. A file that has several hard links is replaced by a new file: the other names keep the old bytes (the operating system does not say which names a file has, so this cannot be seen from here).

public sealed class DirectorySource : IFileSource

Inheritance

object ← DirectorySource

Implements

IFileSource

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

DirectorySource(string, bool)

public DirectorySource(string root, bool writable = false)

Parameters

root string

writable bool

Properties

CanWrite

public bool CanWrite { get; }

Property Value

bool

Description

What the source is, for messages: a folder's path, a zip's file name.

public string Description { get; }

Property Value

string

Root

The folder, as a full path.

public string Root { get; }

Property Value

string

Methods

CreateDirectory(string)

public void CreateDirectory(string path)

Parameters

path string

Delete(string)

Deletes a file, or a folder with what is in it. Does nothing when there is none.

public void Delete(string path)

Parameters

path string

Kind(string)

public FileKind Kind(string path)

Parameters

path string

Returns

FileKind

List(string, List<(string Name, FileKind Kind)>)

Adds the entries directly inside directory to into: their names and kinds, in any order (a source may list entries).

public void List(string directory, List<(string Name, FileKind Kind)> into)

Parameters

directory string

into List<(string Name, FileKind Kind)>

Move(string, string)

Moves a file inside this source to a path that has no file yet, making the folders above it. A source that can move without copying (a folder: one rename) overrides this; the default copies and then deletes, which is what a source that only reads and writes whole files can do.

public void Move(string source, string target)

Parameters

source string

target string

Exceptions

FileNotFoundException

There is no file at source.

IOException

There is already a file at target.

OpenRead(string)

public Stream OpenRead(string path)

Parameters

path string

Returns

Stream

Exceptions

FileNotFoundException

There is no such file.

PhysicalPath(string)

The path in the real file system, when there is one: for watching a file or handing it to a library that wants a path.

public string? PhysicalPath(string path)

Parameters

path string

Returns

string?

ReadAllBytes(string)

public byte[] ReadAllBytes(string path)

Parameters

path string

Returns

byte[]

Exceptions

FileNotFoundException

There is no such file.

WriteAllBytes(string, ReadOnlySpan<byte>)

Writes the file whole, making the folders above it; an interrupted write leaves the old file.

public void WriteAllBytes(string path, ReadOnlySpan<byte> bytes)

Parameters

path string

bytes ReadOnlySpan<byte>