diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index 71babe341c..e285b343e9 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -29,6 +29,11 @@ namespace Tgstation.Server.Host.Controllers [Route(Routes.InstanceManager)] public sealed class InstanceController : ModelController { + /// + /// File name to allow attaching instances + /// + const string InstanceAttachFileName = "TGS4_ALLOW_INSTANCE_ATTACH"; + /// /// The for the /// @@ -107,7 +112,8 @@ namespace Tgstation.Server.Host.Controllers NormalizeModelPath(model, out var rawPath); var dirExistsTask = ioManager.DirectoryExists(model.Path, cancellationToken); if (await ioManager.FileExists(model.Path, cancellationToken).ConfigureAwait(false) || await dirExistsTask.ConfigureAwait(false)) - return Conflict(new ErrorMessage { Message = "Path not empty!" }); + if(!await ioManager.FileExists(ioManager.ConcatPath(model.Path, InstanceAttachFileName), cancellationToken).ConfigureAwait(false)) + return Conflict(new ErrorMessage { Message = "Path not empty!" }); var newInstance = new Models.Instance { @@ -154,7 +160,8 @@ namespace Tgstation.Server.Host.Controllers try { //actually reserve it now - await ioManager.CreateDirectory(rawPath, default).ConfigureAwait(false); + await ioManager.CreateDirectory(rawPath, cancellationToken).ConfigureAwait(false); + await ioManager.DeleteFile(ioManager.ConcatPath(rawPath, InstanceAttachFileName), cancellationToken).ConfigureAwait(false); } catch { @@ -169,7 +176,7 @@ namespace Tgstation.Server.Host.Controllers { return Conflict(new ErrorMessage { Message = e.Message }); } - catch (DbUpdateConcurrencyException e) + catch (DbUpdateException e) { return Conflict(new ErrorMessage{ Message = e.Message }); } @@ -201,7 +208,17 @@ namespace Tgstation.Server.Host.Controllers } DatabaseContext.Instances.Remove(originalModel); - await DatabaseContext.Save(cancellationToken).ConfigureAwait(false); //cascades everything + + var attachFileName = ioManager.ConcatPath(originalModel.Path, InstanceAttachFileName); + await ioManager.WriteAllBytes(attachFileName, Array.Empty(), default).ConfigureAwait(false); + try + { + await DatabaseContext.Save(cancellationToken).ConfigureAwait(false); //cascades everything + } + catch (DbUpdateException e) + { + return Conflict(new ErrorMessage { Message = e.Message }); + } return Ok(); }