From 413d944c8406673ce16d87f3b53827a4ad416b8a Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Tue, 14 Aug 2018 15:35:36 -0400 Subject: [PATCH] Adds directory deletion --- src/Tgstation.Server.Host/IO/SynchronousIOManager.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs b/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs index ec85b710d0..7f29f0b20f 100644 --- a/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs +++ b/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs @@ -53,7 +53,8 @@ namespace Tgstation.Server.Host.IO if (path == null) throw new ArgumentNullException(nameof(path)); cancellationToken.ThrowIfCancellationRequested(); - Directory.CreateDirectory(Path.GetDirectoryName(path)); + var directory = Path.GetDirectoryName(path); + Directory.CreateDirectory(directory); cancellationToken.ThrowIfCancellationRequested(); using (var file = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { @@ -93,7 +94,16 @@ namespace Tgstation.Server.Host.IO } } if (data == null) + { File.Delete(path); + if (!cancellationToken.IsCancellationRequested) + //delete the entire folder if possible + try + { + Directory.Delete(directory); + } + catch (IOException) { } + } return true; } }