diff --git a/src/Tgstation.Server.Api/Models/Internal/Job.cs b/src/Tgstation.Server.Api/Models/Internal/Job.cs index 1b0104c22d..7738cf0043 100644 --- a/src/Tgstation.Server.Api/Models/Internal/Job.cs +++ b/src/Tgstation.Server.Api/Models/Internal/Job.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel.DataAnnotations; using Tgstation.Server.Api.Rights; namespace Tgstation.Server.Api.Models.Internal @@ -19,6 +20,7 @@ namespace Tgstation.Server.Api.Models.Internal /// English description of the /// [Permissions(DenyWrite = true)] + [Required] public string Description { get; set; } /// @@ -37,7 +39,7 @@ namespace Tgstation.Server.Api.Models.Internal /// When the stopped /// [Permissions(DenyWrite = true)] - public DateTimeOffset StoppedAt { get; set; } + public DateTimeOffset? StoppedAt { get; set; } /// /// If the was cancelled diff --git a/src/Tgstation.Server.Api/Models/Internal/User.cs b/src/Tgstation.Server.Api/Models/Internal/User.cs index b70e868079..1e6ab36b2e 100644 --- a/src/Tgstation.Server.Api/Models/Internal/User.cs +++ b/src/Tgstation.Server.Api/Models/Internal/User.cs @@ -27,7 +27,7 @@ namespace Tgstation.Server.Api.Models.Internal /// [Permissions(DenyWrite = true)] [Required] - public DateTimeOffset CreatedAt { get; set; } + public DateTimeOffset? CreatedAt { get; set; } /// /// The SID/UID of the on Windows/POSIX respectively diff --git a/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs b/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs index 6e5079e76c..21c29d5f8c 100644 --- a/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs +++ b/src/Tgstation.Server.Host/Components/Byond/ByondManager.cs @@ -96,19 +96,27 @@ namespace Tgstation.Server.Host.Components.Byond await Task.WhenAny(ourTcs.Task, inProgressTask).ConfigureAwait(false); return; } + try + { + var downloadTask = byondInstaller.DownloadVersion(version, cancellationToken); - var downloadTask = byondInstaller.DownloadVersion(version, cancellationToken); + //okay up to us to install it then + await ioManager.DeleteDirectory(versionKey, cancellationToken).ConfigureAwait(false); + await ioManager.CreateDirectory(versionKey, cancellationToken).ConfigureAwait(false); - //okay up to us to install it then - await ioManager.DeleteDirectory(versionKey, cancellationToken).ConfigureAwait(false); - await ioManager.CreateDirectory(versionKey, cancellationToken).ConfigureAwait(false); + await ioManager.ZipToDirectory(versionKey, await downloadTask.ConfigureAwait(false), cancellationToken).ConfigureAwait(false); - await ioManager.ZipToDirectory(versionKey, await downloadTask.ConfigureAwait(false), cancellationToken).ConfigureAwait(false); + await byondInstaller.InstallByond(ioManager.ResolvePath(versionKey), version, cancellationToken).ConfigureAwait(false); - await byondInstaller.InstallByond(ioManager.ResolvePath(versionKey), version, cancellationToken).ConfigureAwait(false); - - //make sure to do this last because this is what tells us we have a valid version - await ioManager.WriteAllBytes(ioManager.ConcatPath(versionKey, VersionFileName), Encoding.UTF8.GetBytes(version.ToString()), cancellationToken).ConfigureAwait(false); + //make sure to do this last because this is what tells us we have a valid version + await ioManager.WriteAllBytes(ioManager.ConcatPath(versionKey, VersionFileName), Encoding.UTF8.GetBytes(version.ToString()), cancellationToken).ConfigureAwait(false); + } + catch + { + lock (installedVersions) + installedVersions.Remove(versionKey); + throw; + } } /// @@ -159,7 +167,14 @@ namespace Tgstation.Server.Host.Components.Byond async Task ReadVersion(string path) { - var bytes = await ioManager.ReadAllBytes(ioManager.ConcatPath(path, VersionFileName), cancellationToken).ConfigureAwait(false); + var versionFile = ioManager.ConcatPath(path, VersionFileName); + if (!await ioManager.FileExists(versionFile, cancellationToken).ConfigureAwait(false)) + { + logger.LogInformation("Cleaning unparsable version path: {0}", ioManager.ResolvePath(path)); + await ioManager.DeleteDirectory(path, cancellationToken).ConfigureAwait(false); //cleanup + return; + } + var bytes = await ioManager.ReadAllBytes(versionFile, cancellationToken).ConfigureAwait(false); var text = Encoding.UTF8.GetString(bytes); if (Version.TryParse(text, out var version)) { diff --git a/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs b/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs index e1f656e0e2..263f39eb7c 100644 --- a/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs +++ b/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs @@ -89,7 +89,7 @@ namespace Tgstation.Server.Host.Components.Byond /// public async Task InstallByond(string path, Version version, CancellationToken cancellationToken) { - var setNoPromptTrustedModeTask = ioManager.WriteAllBytes(ByondDDConfig, Encoding.UTF8.GetBytes(ByondNoPromptTrustedMode), cancellationToken); + var setNoPromptTrustedModeTask = ioManager.WriteAllBytes(ioManager.ConcatPath(path, ByondDDConfig), Encoding.UTF8.GetBytes(ByondNoPromptTrustedMode), cancellationToken); //after this version lummox made DD depend of directx lol if (version.Major >= 512 && version.Minor >= 1427 && Monitor.TryEnter(this)) diff --git a/src/Tgstation.Server.Host/Controllers/ByondController.cs b/src/Tgstation.Server.Host/Controllers/ByondController.cs index a70c5d80a8..0a6a47f408 100644 --- a/src/Tgstation.Server.Host/Controllers/ByondController.cs +++ b/src/Tgstation.Server.Host/Controllers/ByondController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; +using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -93,6 +94,7 @@ namespace Tgstation.Server.Host.Controllers //run the install through the job manager var job = new Models.Job { + Description = String.Format(CultureInfo.InvariantCulture, "Install BYOND version {0}", installingVersion), StartedBy = AuthenticationContext.User, CancelRightsType = RightsType.Byond, CancelRight = (int)ByondRights.CancelInstall, diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index aab876e91b..53ac454911 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Net; @@ -235,9 +236,10 @@ namespace Tgstation.Server.Host.Controllers }; string originalModelPath = null; + string rawPath = null; if (model.Path != null) { - NormalizeModelPath(model, out var rawPath); + NormalizeModelPath(model, out rawPath); if (model.Path != originalModel.Path) { @@ -301,7 +303,7 @@ namespace Tgstation.Server.Host.Controllers { var job = new Models.Job { - Description = "Move instance location", + Description = String.Format(CultureInfo.InvariantCulture, "Move instance ID {0} from {1} to {2}", Instance.Id, Instance.Path, rawPath), Instance = Instance, CancelRightsType = RightsType.InstanceManager, CancelRight = (int)InstanceManagerRights.CancelMove, @@ -311,7 +313,7 @@ namespace Tgstation.Server.Host.Controllers await jobManager.RegisterOperation(job, async (paramJob, serviceProvider, ct) => { try { - await instanceManager.MoveInstance(Instance, originalModel.Path, ct).ConfigureAwait(false); + await instanceManager.MoveInstance(Instance, rawPath, ct).ConfigureAwait(false); } catch { diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index 2f761f9f9c..97afc62c66 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Linq.Expressions; using System.Net; @@ -146,7 +147,7 @@ namespace Tgstation.Server.Host.Controllers var job = new Models.Job { - Description = "Clone repository", + Description = String.Format(CultureInfo.InvariantCulture, "Clone branch {1} of repository {0}", origin, cloneBranch), StartedBy = AuthenticationContext.User, CancelRightsType = RightsType.Repository, CancelRight = (int)RepositoryRights.CancelClone, diff --git a/src/Tgstation.Server.Host/Models/Job.cs b/src/Tgstation.Server.Host/Models/Job.cs index 4262ea1aff..0b56cca428 100644 --- a/src/Tgstation.Server.Host/Models/Job.cs +++ b/src/Tgstation.Server.Host/Models/Job.cs @@ -29,7 +29,7 @@ namespace Tgstation.Server.Host.Models StartedAt = StartedAt, StoppedAt = StoppedAt, Cancelled = Cancelled, - CancelledBy = CancelledBy.ToApi(), + CancelledBy = CancelledBy?.ToApi(), CancelRight = CancelRight, CancelRightsType = CancelRightsType, Description = Description,