From 7023baaecd9105cedf8d94d8b5a3304698820e9d Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 7 Aug 2018 20:16:56 -0400 Subject: [PATCH] Fix symlinking invocations when the path already exists --- .../Components/StaticFiles/Configuration.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs index 92595de192..c62ee59bc5 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs @@ -224,7 +224,19 @@ namespace Tgstation.Server.Host.Components.StaticFiles else task = ioManager.GetDirectories(GameStaticFilesSubdirectory, cancellationToken); var entries = await task.ConfigureAwait(false); - await Task.WhenAll(entries.Select(x => symlinkFactory.CreateSymbolicLink(ioManager.ResolvePath(x), ioManager.ConcatPath(destination, x), cancellationToken))).ConfigureAwait(false); + + await Task.WhenAll(task.Result.Select(async x => + { + var destPath = ioManager.ConcatPath(destination, ioManager.GetFileName(x)); + logger.LogTrace("Symlinking {0} to {1}...", x, destPath); + var fileExistsTask = ioManager.FileExists(destPath, cancellationToken); + if (await ioManager.DirectoryExists(destPath, cancellationToken).ConfigureAwait(false)) + await ioManager.DeleteDirectory(destPath, cancellationToken).ConfigureAwait(false); + var fileExists = await fileExistsTask.ConfigureAwait(false); + if (fileExists) + await ioManager.DeleteFile(destPath, cancellationToken).ConfigureAwait(false); + await symlinkFactory.CreateSymbolicLink(ioManager.ResolvePath(x), ioManager.ResolvePath(destPath), cancellationToken).ConfigureAwait(false); + })).ConfigureAwait(false); } await Task.WhenAll(SymlinkBase(true), SymlinkBase(false)).ConfigureAwait(false);