Class WorkspaceLock

Namespace
Kuestenlogik.Bowire.Workspace.Git
Assembly
Kuestenlogik.Bowire.Workspace.Git.dll

Cross-process workspace lockfile — guards concurrent writers against corrupting the per-entity layout. One holder per storageRoot; second writer hitting an active lock surfaces the friendly "another process is editing this workspace" hint instead of overwriting state.

public sealed class WorkspaceLock : IAsyncDisposable, IDisposable
Inheritance
WorkspaceLock
Implements
Inherited Members

Remarks

On AcquireAsync(string, string, CancellationToken) the lock file lives at <storageRoot>/.bowire.lock as a small JSON blob with pid, writer, host, startedAtUtc. The FileStream stays open for the lifetime of the lock (share = Read) so a second process can READ the metadata but not delete or replace the file.

Stale-lock recovery: if an existing lock's pid no longer maps to a live process (the holder crashed) the acquirer takes over — safety-net for "I rebooted in the middle of a save". Within the same process, two writers serialize on the OS file-handle: the second hits IOException immediately because CreateNew refuses to clobber.

Fields

FileName

File name of the per-workspace lock at the root.

public const string FileName = ".bowire.lock"

Field Value

string

Methods

AcquireAsync(string, string, CancellationToken)

Metadata for the writer currently holding the lock. Populated in LockHeldException so the caller can surface a friendly diagnostic without re-reading the file.

public static Task<WorkspaceLock> AcquireAsync(string storageRoot, string writerName, CancellationToken ct = default)

Parameters

storageRoot string

Absolute path to the workspace root.

writerName string

Holder tag — short identifier of the calling subsystem.

ct CancellationToken

Cancellation token.

Returns

Task<WorkspaceLock>

Exceptions

ArgumentException

storageRoot is null / whitespace / missing.

LockHeldException

Another live process already holds the lock.

Dispose()

public void Dispose()

DisposeAsync()

public ValueTask DisposeAsync()

Returns

ValueTask

Inspect(string)

Read the current holder's metadata without acquiring the lock. Returns null when no lock is present, the file is unreadable, or the JSON is malformed. Useful for diagnostics in the CLI (e.g. bowire workspace status).

public static WorkspaceLockInfo? Inspect(string storageRoot)

Parameters

storageRoot string

Returns

WorkspaceLockInfo?