Write to the trusted.txt in the user's BYOND folder

This commit is contained in:
Jordan Brown
2020-04-22 12:12:27 -04:00
parent d333ca3387
commit c08c839074
@@ -22,9 +22,14 @@ namespace Tgstation.Server.Host.Components.Byond
public const string BinPath = "byond/bin";
/// <summary>
/// The path to the BYOND bin folder
/// The path to the cfg directory.
/// </summary>
const string TrustedDmbListPath = "byond/cfg/trusted.txt";
const string CfgDirectoryName = "cfg";
/// <summary>
/// The name of the list of trusted .dmb files in the user's BYOND cfg directory.
/// </summary>
const string TrustedDmbFileName = "trusted.txt";
/// <summary>
/// The file in which we store the <see cref="VersionKey(Version)"/> for installations
@@ -205,14 +210,25 @@ namespace Tgstation.Server.Host.Components.Byond
await InstallVersion(versionToUse, cancellationToken).ConfigureAwait(false);
var versionKey = VersionKey(versionToUse);
var binPathForVersion = ioManager.ConcatPath(versionKey, BinPath);
return new ByondExecutableLock(
ioManager,
semaphore,
versionToUse,
ioManager.ResolvePath(ioManager.ConcatPath(versionKey, BinPath, byondInstaller.DreamDaemonName)),
ioManager.ResolvePath(ioManager.ConcatPath(versionKey, BinPath, byondInstaller.DreamMakerName)),
ioManager.ResolvePath(ioManager.ConcatPath(versionKey, TrustedDmbListPath)));
ioManager.ResolvePath(
ioManager.ConcatPath(
binPathForVersion,
byondInstaller.DreamDaemonName)),
ioManager.ResolvePath(
ioManager.ConcatPath(
binPathForVersion,
byondInstaller.DreamMakerName)),
ioManager.ResolvePath(
ioManager.ConcatPath(
byondInstaller.PathToUserByondFolder,
CfgDirectoryName,
TrustedDmbFileName)));
}
/// <inheritdoc />
@@ -226,6 +242,24 @@ namespace Tgstation.Server.Host.Components.Byond
var activeVersionBytesTask = GetActiveVersion();
// Create local cfg directory in case it doesn't exist
var localCfgDirectory = ioManager.ConcatPath(
byondInstaller.PathToUserByondFolder,
CfgDirectoryName);
await ioManager.CreateDirectory(
localCfgDirectory,
cancellationToken).ConfigureAwait(false);
// No need to do this on dev machines
#if !DEBUG
// Delete trusted.txt so it doesn't grow too large
await ioManager.DeleteFile(
ioManager.ConcatPath(
localCfgDirectory,
TrustedDmbFileName),
cancellationToken).ConfigureAwait(false);
#endif
await ioManager.CreateDirectory(".", cancellationToken).ConfigureAwait(false);
var directories = await ioManager.GetDirectories(".", cancellationToken).ConfigureAwait(false);
@@ -239,9 +273,6 @@ namespace Tgstation.Server.Host.Components.Byond
return;
}
// Delete trusted.txt so it doesn't grow too large
await ioManager.DeleteFile(ioManager.ConcatPath(path, TrustedDmbListPath), cancellationToken).ConfigureAwait(false);
var bytes = await ioManager.ReadAllBytes(versionFile, cancellationToken).ConfigureAwait(false);
var text = Encoding.UTF8.GetString(bytes);
if (Version.TryParse(text, out var version))