tgstation-server 5.12.7
The /tg/station 13 server suite
Loading...
Searching...
No Matches
SwappableDmbProvider.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
7
9{
14 {
18 public const string LiveGameDirectory = "Live";
19
21 public string DmbName => baseProvider.DmbName;
22
25
28
32 public bool Swapped => swapped != 0;
33
38
43
48
52 volatile int swapped;
53
61 {
62 this.baseProvider = baseProvider ?? throw new ArgumentNullException(nameof(baseProvider));
63 this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
64 this.symlinkFactory = symlinkFactory ?? throw new ArgumentNullException(nameof(symlinkFactory));
65 }
66
68 public void Dispose() => baseProvider.Dispose();
69
71 public void KeepAlive() => baseProvider.KeepAlive();
72
78 public async Task MakeActive(CancellationToken cancellationToken)
79 {
80 if (Interlocked.Exchange(ref swapped, 1) != 0)
81 throw new InvalidOperationException("Already swapped!");
82
84 await ioManager.DeleteFile(LiveGameDirectory, cancellationToken);
85 else
86 await ioManager.DeleteDirectory(LiveGameDirectory, cancellationToken);
87
91 cancellationToken);
92 }
93 }
94}
string Directory
The primary game directory with a trailing directory separator.
readonly IDmbProvider baseProvider
The IDmbProvider we are swapping for.
void KeepAlive()
Disposing the IDmbProvider won't cause a cleanup of the working directory.
bool Swapped
If MakeActive(CancellationToken) has been run.
async Task MakeActive(CancellationToken cancellationToken)
Make the SwappableDmbProvider active by replacing the live link with our CompileJob.
readonly ISymlinkFactory symlinkFactory
The ISymlinkFactory to use.
const string LiveGameDirectory
The directory where the baseProvider is symlinked to.
SwappableDmbProvider(IDmbProvider baseProvider, IIOManager ioManager, ISymlinkFactory symlinkFactory)
Initializes a new instance of the SwappableDmbProvider class.
Provides absolute paths to the latest compiled .dmbs.
Definition: IDmbProvider.cs:11
void KeepAlive()
Disposing the IDmbProvider won't cause a cleanup of the working directory.
string Directory
The primary game directory with a trailing directory separator.
Definition: IDmbProvider.cs:20
CompileJob CompileJob
The CompileJob of the .dmb.
Definition: IDmbProvider.cs:25
Interface for using filesystems.
Definition: IIOManager.cs:13
string ResolvePath()
Retrieve the full path of the current working directory.
Task DeleteFile(string path, CancellationToken cancellationToken)
Deletes a file at path .
Task DeleteDirectory(string path, CancellationToken cancellationToken)
Recursively delete a directory, removes and does not enter any symlinks encounterd.