Nullify Configuration

This commit is contained in:
Jordan Dominion
2023-12-20 23:20:20 -05:00
parent 9bab2f5d5a
commit 921b2b44fc
5 changed files with 29 additions and 24 deletions
@@ -23,8 +23,6 @@ using Tgstation.Server.Host.System;
using Tgstation.Server.Host.Transfer;
using Tgstation.Server.Host.Utils;
#nullable disable
namespace Tgstation.Server.Host.Components.StaticFiles
{
/// <inheritdoc />
@@ -80,7 +78,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
eventType => new KeyValuePair<EventType, IReadOnlyList<string>>(
eventType,
typeof(EventType)
.GetField(eventType.ToString())
.GetField(eventType.ToString())!
.GetCustomAttributes(false)
.OfType<EventScriptAttribute>()
.First()
@@ -201,7 +199,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async ValueTask<ServerSideModifications> CopyDMFilesTo(string dmeFile, string destination, CancellationToken cancellationToken)
public async ValueTask<ServerSideModifications?> CopyDMFilesTo(string dmeFile, string destination, CancellationToken cancellationToken)
{
using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken))
{
@@ -234,12 +232,19 @@ namespace Tgstation.Server.Host.Components.StaticFiles
static string IncludeLine(string filePath) => String.Format(CultureInfo.InvariantCulture, "#include \"{0}\"", filePath);
return new ServerSideModifications(headFileExistsTask.Result ? IncludeLine(CodeModificationsHeadFile) : null, tailFileExistsTask.Result ? IncludeLine(CodeModificationsTailFile) : null, false);
return new ServerSideModifications(
headFileExistsTask.Result
? IncludeLine(CodeModificationsHeadFile)
: null,
tailFileExistsTask.Result
? IncludeLine(CodeModificationsTailFile)
: null,
false);
}
}
/// <inheritdoc />
public async ValueTask<IOrderedQueryable<ConfigurationFileResponse>> ListDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
public async ValueTask<IOrderedQueryable<ConfigurationFileResponse>?> ListDirectory(string? configurationRelativePath, ISystemIdentity? systemIdentity, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
@@ -286,12 +291,12 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async ValueTask<ConfigurationFileResponse> Read(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
public async ValueTask<ConfigurationFileResponse?> Read(string configurationRelativePath, ISystemIdentity? systemIdentity, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
ConfigurationFileResponse result = null;
ConfigurationFileResponse? result = null;
void ReadImpl()
{
@@ -321,7 +326,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
},
async cancellationToken =>
{
FileStream result = null;
FileStream? result = null;
void GetFileStream()
{
result = ioManager.GetFileStream(path, false);
@@ -332,7 +337,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
else
await systemIdentity.RunImpersonated(GetFileStream, cancellationToken);
return result;
return result!;
},
path,
false));
@@ -453,12 +458,12 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async ValueTask<ConfigurationFileResponse> Write(string configurationRelativePath, ISystemIdentity systemIdentity, string previousHash, CancellationToken cancellationToken)
public async ValueTask<ConfigurationFileResponse?> Write(string configurationRelativePath, ISystemIdentity? systemIdentity, string? previousHash, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
ConfigurationFileResponse result = null;
ConfigurationFileResponse? result = null;
void WriteImpl()
{
@@ -563,7 +568,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async ValueTask<bool?> CreateDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
public async ValueTask<bool?> CreateDirectory(string configurationRelativePath, ISystemIdentity? systemIdentity, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
@@ -585,7 +590,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
await systemIdentity.RunImpersonated(DoCreate, cancellationToken);
}
return result.Value;
return result!.Value;
}
/// <inheritdoc />
@@ -659,7 +664,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async ValueTask<bool?> DeleteDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
public async ValueTask<bool?> DeleteDirectory(string configurationRelativePath, ISystemIdentity? systemIdentity, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
@@ -737,16 +742,16 @@ namespace Tgstation.Server.Host.Components.StaticFiles
/// </summary>
/// <param name="configurationRelativePath">A relative path in the instance's configuration directory.</param>
/// <returns>The full on-disk path of <paramref name="configurationRelativePath"/>.</returns>
string ValidateConfigRelativePath(string configurationRelativePath)
string ValidateConfigRelativePath(string? configurationRelativePath)
{
var nullOrEmptyCheck = String.IsNullOrEmpty(configurationRelativePath);
if (nullOrEmptyCheck)
configurationRelativePath = DefaultIOManager.CurrentDirectory;
if (configurationRelativePath[0] == Path.DirectorySeparatorChar || configurationRelativePath[0] == Path.AltDirectorySeparatorChar)
if (configurationRelativePath![0] == Path.DirectorySeparatorChar || configurationRelativePath[0] == Path.AltDirectorySeparatorChar)
configurationRelativePath = DefaultIOManager.CurrentDirectory + configurationRelativePath;
var resolved = ioManager.ResolvePath(configurationRelativePath);
var local = !nullOrEmptyCheck ? ioManager.ResolvePath() : null;
if (!nullOrEmptyCheck && resolved.Length < local.Length) // .. fuccbois
if (!nullOrEmptyCheck && resolved.Length < local!.Length) // .. fuccbois
throw new InvalidOperationException("Attempted to access file outside of configuration manager!");
return resolved;
}
@@ -39,7 +39,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
/// <param name="systemIdentity">The <see cref="ISystemIdentity"/> for the operation. If <see langword="null"/>, the operation will be performed as the user of the <see cref="Core.Application"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in an <see cref="IOrderedQueryable{T}"/> of the <see cref="ConfigurationFileResponse"/>s for the items in the directory. <see cref="FileTicketResponse.FileTicket"/> and <see cref="IConfigurationFile.LastReadHash"/> will both be <see langword="null"/>. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
ValueTask<IOrderedQueryable<ConfigurationFileResponse>> ListDirectory(string? configurationRelativePath, ISystemIdentity? systemIdentity, CancellationToken cancellationToken);
ValueTask<IOrderedQueryable<ConfigurationFileResponse>?> ListDirectory(string? configurationRelativePath, ISystemIdentity? systemIdentity, CancellationToken cancellationToken);
/// <summary>
/// Reads a given <paramref name="configurationRelativePath"/>.
@@ -13,12 +13,12 @@
/// <summary>
/// The #include line which should be added to the beginning of the .dme if any.
/// </summary>
public string HeadIncludeLine { get; }
public string? HeadIncludeLine { get; }
/// <summary>
/// The #include line which should be added to the end of the .dme if any.
/// </summary>
public string TailIncludeLine { get; }
public string? TailIncludeLine { get; }
/// <summary>
/// Initializes a new instance of the <see cref="ServerSideModifications"/> class.
@@ -26,7 +26,7 @@
/// <param name="headIncludeLine">The value of <see cref="HeadIncludeLine"/>.</param>
/// <param name="tailIncludeLine">The value of <see cref="TailIncludeLine"/>.</param>
/// <param name="totalDmeOverwrite">The value of <see cref="TotalDmeOverwrite"/>.</param>
public ServerSideModifications(string headIncludeLine, string tailIncludeLine, bool totalDmeOverwrite)
public ServerSideModifications(string? headIncludeLine, string? tailIncludeLine, bool totalDmeOverwrite)
{
HeadIncludeLine = headIncludeLine;
TailIncludeLine = tailIncludeLine;
@@ -69,7 +69,7 @@ namespace Tgstation.Server.Host.IO
/// <inheritdoc />
public async ValueTask CopyDirectory(
IEnumerable<string> ignore,
IEnumerable<string>? ignore,
Func<string, string, ValueTask>? postCopyCallback,
string src,
string dest,
+1 -1
View File
@@ -56,7 +56,7 @@ namespace Tgstation.Server.Host.IO
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask CopyDirectory(
IEnumerable<string> ignore,
IEnumerable<string>? ignore,
Func<string, string, ValueTask>? postCopyCallback,
string src,
string dest,