Some stuff

This commit is contained in:
Jordan Brown
2018-07-22 19:30:52 -04:00
parent cf1bbb73f2
commit eb925ea4cd
5 changed files with 29 additions and 3 deletions
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Api.Models;
@@ -42,7 +43,7 @@ namespace Tgstation.Server.Host.Components
}
/// <inheritdoc />
public async Task<ServerSideModifications> CopyDMFilesTo(string destination, CancellationToken cancellationToken)
public async Task<ServerSideModifications> CopyDMFilesTo(string dmeFile, string destination, CancellationToken cancellationToken)
{
//just assume no other fs race conditions here
var dmeExistsTask = ioManager.FileExists(ioManager.ConcatPath(CodeModificationsSubdirectory, dmeFile), cancellationToken);
@@ -77,6 +78,9 @@ namespace Tgstation.Server.Host.Components
/// <inheritdoc />
public Task<IReadOnlyList<ConfigurationFile>> ListDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
{
if (String.IsNullOrEmpty(configurationRelativePath))
configurationRelativePath = ".";
throw new NotImplementedException();
}
@@ -191,7 +191,7 @@ namespace Tgstation.Server.Host.Components
var dmePath = ioManager.ConcatPath(dirA, String.Concat(job.DmeName, DmeExtension));
var dmeReadTask = ioManager.ReadAllBytes(dmePath, cancellationToken);
var dmeModificationsTask = configuration.CopyDMFilesTo(ioManager.ResolvePath(dirA), cancellationToken);
var dmeModificationsTask = configuration.CopyDMFilesTo(dmePath, ioManager.ResolvePath(dirA), cancellationToken);
var dmeBytes = await dmeReadTask.ConfigureAwait(false);
var dme = Encoding.UTF8.GetString(dmeBytes);
@@ -14,10 +14,11 @@ namespace Tgstation.Server.Host.Components
/// <summary>
/// Copies all files in the CodeModifications directory to <paramref name="destination"/>
/// </summary>
/// <param name="dmeFile">The .dme file being compiled</param>
/// <param name="destination">Path to the destination folder</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ServerSideModifications"/> if any</returns>
Task<ServerSideModifications> CopyDMFilesTo(string destination, CancellationToken cancellationToken);
Task<ServerSideModifications> CopyDMFilesTo(string dmeFile, string destination, CancellationToken cancellationToken);
/// <summary>
/// Symlinks all directories in the GameData directory to <paramref name="destination"/>
@@ -220,5 +220,18 @@ namespace Tgstation.Server.Host.Core
}
return (IReadOnlyList<string>)results;
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
/// <inheritdoc />
public Task<IReadOnlyList<string>> GetFiles(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() =>
{
path = ResolvePath(path);
var results = new List<string>();
foreach (var I in Directory.EnumerateFiles(path))
{
cancellationToken.ThrowIfCancellationRequested();
results.Add(I);
}
return (IReadOnlyList<string>)results;
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
}
}
@@ -72,6 +72,14 @@ namespace Tgstation.Server.Host.Core
/// <returns>A <see cref="Task{TResult}"/> resulting in the directories in <paramref name="path"/></returns>
Task<IReadOnlyList<string>> GetDirectories(string path, CancellationToken cancellationToken);
/// <summary>
/// Returns file names in a given <paramref name="path"/>
/// </summary>
/// <param name="path">The path to search for files</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the files in <paramref name="path"/></returns>
Task<IReadOnlyList<string>> GetFiles(string path, CancellationToken cancellationToken);
/// <summary>
/// Writes some <paramref name="contents"/> to a file at <paramref name="path"/> overwriting previous content
/// </summary>