From 8ae91abaf8942954988dec14a4de7eb56781978d Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 23 Jul 2018 12:41:02 -0400 Subject: [PATCH] Implement Components.Configuration.ListDirectory --- .../Components/Configuration.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Configuration.cs b/src/Tgstation.Server.Host/Components/Configuration.cs index 36e1934498..1ab7412e7d 100644 --- a/src/Tgstation.Server.Host/Components/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/Configuration.cs @@ -83,12 +83,37 @@ namespace Tgstation.Server.Host.Components } /// - public Task> ListDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken) + public async Task> ListDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken) { if (String.IsNullOrEmpty(configurationRelativePath)) configurationRelativePath = "."; - throw new NotImplementedException(); + var path = ioManager.ResolvePath(configurationRelativePath); + + List result = new List(); + + void ListImpl() + { + var enumerator = synchronousIOManager.GetDirectories(configurationRelativePath, cancellationToken); + result.AddRange(enumerator.Select(x => new ConfigurationFile + { + IsDirectory = true, + Path = ioManager.ConcatPath(path, x), + })); + enumerator = synchronousIOManager.GetFiles(configurationRelativePath, cancellationToken); + result.AddRange(enumerator.Select(x => new ConfigurationFile + { + IsDirectory = false, + Path = ioManager.ConcatPath(path, x), + })); + } + + if (systemIdentity == null) + ListImpl(); + else + await systemIdentity.RunImpersonated(ListImpl, cancellationToken).ConfigureAwait(false); + + return result; } ///