Class BowirePathResolver

Namespace
Kuestenlogik.Bowire.Projects
Assembly
Kuestenlogik.Bowire.dll

The default IBowirePathResolver.

public sealed class BowirePathResolver : IBowirePathResolver
Inheritance
BowirePathResolver
Implements
Inherited Members

Remarks

Constructible without a container on purpose: several call sites resolve paths from static initialisers that run before any host is built, and a resolver they cannot reach would just mean those keep their own copy of the logic, which is the problem this type exists to end.

Constructors

BowirePathResolver()

A resolver reading the real environment.

public BowirePathResolver()

BowirePathResolver(Func<string, string?>, Func<string>)

A resolver with both of its inputs supplied.

public BowirePathResolver(Func<string, string?> environment, Func<string> dataRoot)

Parameters

environment Func<string, string>

Reads an environment variable, or null.

dataRoot Func<string>

The Data root before an instance segment is applied — normally whatever BowireStorageRoot decided for this process.

Fields

DataDirVariable

Redirects every scope at one directory. For test fixtures.

public const string DataDirVariable = "BOWIRE_DATA_DIR"

Field Value

string

InstanceVariable

Adds one path segment under each root, separating co-located instances.

public const string InstanceVariable = "BOWIRE_INSTANCE"

Field Value

string

ReservedInstanceNames

Names an instance may not take.

public static readonly IReadOnlySet<string> ReservedInstanceNames

Field Value

IReadOnlySet<string>

Remarks

With no instance set the scope is the root, so an instance named after something the root already contains would share state with an unnamed one — which is the exact opposite of what setting it was meant to achieve, and would fail quietly.

Methods

DataDirOverride(Func<string, string?>?)

The BOWIRE_DATA_DIR override, or null when it is unset (#643).

public static string? DataDirOverride(Func<string, string?>? environment = null)

Parameters

environment Func<string, string>

How to read it. Defaults to the process environment; tests pass their own so they need not mutate a process-global.

Returns

string

Remarks

Public because BowireStorageRoot has to ask the same question, and asking it twice is how the two answers came apart: this resolver honoured the variable while the user store — and so every workspace-scoped path — did not. A run that believed it was isolated wrote into the real ~/.bowire.

Resolve(BowireStorageScope, params string[])

An absolute path under scope's root.

public string Resolve(BowireStorageScope scope, params string[] segments)

Parameters

scope BowireStorageScope

Which root to resolve under.

segments string[]

Relative segments — "plugins", "collections.json". Rooted segments are rejected rather than silently replacing the root, which is what Combine(string, string) would do.

Returns

string

Root(BowireStorageScope)

The root for scope, with no segments added.

public string Root(BowireStorageScope scope)

Parameters

scope BowireStorageScope

Returns

string

ValidateInstance(string)

Reject an instance name that cannot do its job, loudly.

public static void ValidateInstance(string instance)

Parameters

instance string

Remarks

Loudly, because every failure here is silent otherwise: a name with a separator writes outside the root, and a reserved name shares state with the unnamed instance. Both look like they worked.

Exceptions

InvalidOperationException

The name is unusable.