Always bringing things together

This commit is contained in:
Jordan Brown
2018-07-30 11:01:49 -04:00
parent 7dc4118936
commit 8ce8018673
8 changed files with 40 additions and 18 deletions
@@ -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 <see cref="Job"/>
/// </summary>
[Permissions(DenyWrite = true)]
[Required]
public string Description { get; set; }
/// <summary>
@@ -37,7 +39,7 @@ namespace Tgstation.Server.Api.Models.Internal
/// When the <see cref="Job"/> stopped
/// </summary>
[Permissions(DenyWrite = true)]
public DateTimeOffset StoppedAt { get; set; }
public DateTimeOffset? StoppedAt { get; set; }
/// <summary>
/// If the <see cref="Job"/> was cancelled
@@ -27,7 +27,7 @@ namespace Tgstation.Server.Api.Models.Internal
/// </summary>
[Permissions(DenyWrite = true)]
[Required]
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
/// <summary>
/// The SID/UID of the <see cref="User"/> on Windows/POSIX respectively
@@ -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;
}
}
/// <inheritdoc />
@@ -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))
{
@@ -89,7 +89,7 @@ namespace Tgstation.Server.Host.Components.Byond
/// <inheritdoc />
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))
@@ -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,
@@ -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
{
@@ -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,
+1 -1
View File
@@ -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,