Table of Contents

Class SharedPlatformRoot

Namespace
RDCore.SDK.Platform
Assembly
RDCore.SDK.Protocol.dll

The folder every program of a user deploys the platform into, whichever comes first: rdc install, or an IDE add-in's platform installer. Each deploys it by these rules, so that each finds what the other deployed.

public sealed class SharedPlatformRoot
Inheritance
SharedPlatformRoot
Inherited Members

Remarks

A deployed version is never changed. Each one is deployed beside the others, under versions/<version>, named by Text. It is first written whole into a .partial folder beside it (PartialRoot(PlatformVersion)), and moved into place once it is a whole platform (MoveIntoPlace(PlatformVersion)).

One version is current, as installer.json names it: {"Current":"0.2.0","Previous":"0.1.0"}. A version older than the current one is deployed beside it, and not made current (MakeCurrentUnlessOlder(PlatformVersion)).

One deployment at a time, across processes: install.lock is held open, unshared, for the whole of one (LockAsync(Action?, CancellationToken)).

Old versions are removed whole, or not at all (RemoveOldVersions(PlatformVersion)): the current one and the one before it are kept. A version is renamed out of the way first. On Windows the rename fails while a process runs from the version, which is then left where it is until a later deployment finds it unused.

A held version is not removed (Hold(DeployedPlatform)): a program holds the version a server runs from for as long as the server runs, whichever program deployed it, and a removal leaves that version where it is, on every system.

Constructors

SharedPlatformRoot(string)

The folder every program of a user deploys the platform into, whichever comes first: rdc install, or an IDE add-in's platform installer. Each deploys it by these rules, so that each finds what the other deployed.

public SharedPlatformRoot(string root)

Parameters

root string

The root's folder, such as ForThisUser.

Remarks

A deployed version is never changed. Each one is deployed beside the others, under versions/<version>, named by Text. It is first written whole into a .partial folder beside it (PartialRoot(PlatformVersion)), and moved into place once it is a whole platform (MoveIntoPlace(PlatformVersion)).

One version is current, as installer.json names it: {"Current":"0.2.0","Previous":"0.1.0"}. A version older than the current one is deployed beside it, and not made current (MakeCurrentUnlessOlder(PlatformVersion)).

One deployment at a time, across processes: install.lock is held open, unshared, for the whole of one (LockAsync(Action?, CancellationToken)).

Old versions are removed whole, or not at all (RemoveOldVersions(PlatformVersion)): the current one and the one before it are kept. A version is renamed out of the way first. On Windows the rename fails while a process runs from the version, which is then left where it is until a later deployment finds it unused.

A held version is not removed (Hold(DeployedPlatform)): a program holds the version a server runs from for as long as the server runs, whichever program deployed it, and a removal leaves that version where it is, on every system.

Fields

LockFileName

The name of the file held for one deployment: install.lock.

public const string LockFileName = "install.lock"

Field Value

string

PartialSuffix

The suffix of a version's folder while it is written: .partial.

public const string PartialSuffix = ".partial"

Field Value

string

RemovingSuffix

The suffix of a version's folder while it is removed: .removing.

public const string RemovingSuffix = ".removing"

Field Value

string

StateFileName

The name of the file that names the current version and the one before it: installer.json.

public const string StateFileName = "installer.json"

Field Value

string

VersionsFolderName

The name of the folder deployed versions are in: versions.

public const string VersionsFolderName = "versions"

Field Value

string

Properties

Current

The platform in use, or null when none is named, or the one named is gone, or is not a whole platform.

public DeployedPlatform? Current { get; }

Property Value

DeployedPlatform

ForThisUser

The shared root of this user: RDCore/Platform in the local application data folder, which is RDCore's own, not any one program's.

public static string ForThisUser { get; }

Property Value

string

Previous

The version installer.json names as the one before the current one, or null when it names none.

public PlatformVersion? Previous { get; }

Property Value

PlatformVersion

Root

The root's folder.

public string Root { get; }

Property Value

string

Versions

The folder deployed versions are in.

public string Versions { get; }

Property Value

string

Methods

Hold(DeployedPlatform)

Keeps platform deployed for as long as the lease is held: RemoveOldVersions(PlatformVersion) leaves it where it is. Hold it while a server runs from it, and dispose of it once the server has stopped. Any number of programs can hold the same version, and the system releases a lease with the process that holds it.

public static IDisposable Hold(DeployedPlatform platform)

Parameters

platform DeployedPlatform

The deployed version, such as Current.

Returns

IDisposable

The lease: dispose of it to release the version.

Remarks

The lease is the version's manifest, held open for reading and shared for reading only. A removal checks it by opening the manifest unshared, which fails while any lease holds it.

On Windows the open manifest also stops the version's folder from being renamed or deleted by anything else. On Linux and macOS, .NET takes an advisory lock (flock) for a shared file: RemoveOldVersions(PlatformVersion) honors it, and a program that deletes the folder without asking does not. There, a process run with DOTNET_SYSTEM_IO_DISABLEFILELOCKING set takes no lock, and its lease keeps nothing deployed.

Exceptions

FileNotFoundException

The version has no manifest.

DirectoryNotFoundException

The version is not deployed.

IsWhole(string)

Whether folder is a whole platform: one whose rdcore.json names a language server it has, as FindLanguageServer(string) finds it.

public static bool IsWhole(string folder)

Parameters

folder string

The folder of a platform's rdcore.json.

Returns

bool

LockAsync(Action?, CancellationToken)

Holds the root for one deployment, across processes: an exclusive handle on install.lock, released with the handle, and by the system if the process dies holding it. It creates the root when it is not there.

public Task<IDisposable> LockAsync(Action? waiting, CancellationToken cancellationToken)

Parameters

waiting Action

Told once, when another deployment holds the root; null tells no one.

cancellationToken CancellationToken

Stops the wait.

Returns

Task<IDisposable>

The hold: dispose it when the deployment is done.

MakeCurrentUnlessOlder(PlatformVersion)

Makes version, deployed, the platform in use, unless the current one is newer. The current one becomes the previous one. Call it with the root held.

public bool MakeCurrentUnlessOlder(PlatformVersion version)

Parameters

version PlatformVersion

A deployed version.

Returns

bool

Whether version is the current version afterwards.

MoveIntoPlace(PlatformVersion)

Moves version's PartialRoot(PlatformVersion), written whole, into place, as the version's folder. A folder of that version that is not a whole platform is what an interrupted deployment left, and is replaced. Call it with the root held.

public void MoveIntoPlace(PlatformVersion version)

Parameters

version PlatformVersion

The version written.

Exceptions

DirectoryNotFoundException

The partial folder is not there.

FileNotFoundException

The partial folder has no manifest, or lacks the language server its manifest names.

InvalidDataException

The partial folder's manifest is not one, or names a language server outside it.

PartialRoot(PlatformVersion)

Where version is written before it is moved into place: its folder, with PartialSuffix.

public string PartialRoot(PlatformVersion version)

Parameters

version PlatformVersion

The version.

Returns

string

RemoveOldVersions(PlatformVersion)

Removes every deployed version but the current one, the one before it and keep, each one whole: renamed out of the way with RemovingSuffix first, then deleted. On Windows the rename fails while a process runs from the version. A version that cannot be renamed or deleted is left for a later deployment. A folder whose name is not a version is left as it is. Call it with the root held.

public void RemoveOldVersions(PlatformVersion keep)

Parameters

keep PlatformVersion

A version kept as well, such as the one just deployed.

Remarks

A version that is held (Hold(DeployedPlatform)) is kept too. A held one that an earlier removal left renamed is put back where the system allows the rename, and left as it is on Windows, where it does not.

VersionRoot(PlatformVersion)

Where version is, or would be, deployed.

public string VersionRoot(PlatformVersion version)

Parameters

version PlatformVersion

The version.

Returns

string