|
|
|
@@ -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;
|
|
|
|
|
}
|
|
|
|
|