aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Files/FileService.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-06-21 10:57:02 -0500
committerJP Dillingham <jp@dillingham.me>2023-06-21 10:57:02 -0500
commitbf1a9b9effecf8fc18528da672990bc1ed85d6eb (patch)
tree1d3169879207fd1777783bc7764d8819a6a0ce8b /src/slskd/Files/FileService.cs
parent6a79a80932860b9c3ec78fcdd0d169d2efa09005 (diff)
downloadslskd-bf1a9b9effecf8fc18528da672990bc1ed85d6eb.tar.gz
return files + dirs together
Diffstat (limited to 'src/slskd/Files/FileService.cs')
-rw-r--r--src/slskd/Files/FileService.cs22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs
index c7c0105c..dfb5ad7b 100644
--- a/src/slskd/Files/FileService.cs
+++ b/src/slskd/Files/FileService.cs
@@ -42,7 +42,7 @@ namespace slskd.Files
private IOptionsSnapshot<Options> OptionsSnapshot { get; }
/// <summary>
- /// Lists all of the contents of the specified <paramref name="parentDirectory"/>, optionally applying the
+ /// Lists the contents in the specified <paramref name="parentDirectory"/>, optionally applying the
/// specified <paramref name="enumerationOptions"/>.
/// </summary>
/// <param name="parentDirectory">The directory from which to start the listing.</param>
@@ -52,7 +52,7 @@ namespace slskd.Files
/// Thrown if the specified directory is not rooted in an allowed directory.
/// </exception>
/// <exception cref="NotFoundException">Thrown if the specified directory does not exist.</exception>
- public async Task<IEnumerable<FileSystemInfo>> ListContentsAsync(string parentDirectory, EnumerationOptions enumerationOptions = null)
+ public async Task<IEnumerable<FilesystemDirectory>> ListContentsAsync(string parentDirectory, EnumerationOptions enumerationOptions = null)
{
if (!IsPermissibleDirectory(parentDirectory, OptionsSnapshot.Value.Directories))
{
@@ -64,7 +64,23 @@ namespace slskd.Files
throw new NotFoundException($"The directory '{parentDirectory}' does not exist");
}
- return await Task.Run(() => new DirectoryInfo(parentDirectory).GetFileSystemInfos("*", enumerationOptions));
+ return await Task.Run(() =>
+ {
+ var dir = new DirectoryInfo(parentDirectory);
+
+ var contents = dir.GetFileSystemInfos("*", enumerationOptions);
+
+ var files = contents
+ .OfType<FileInfo>()
+ .Select(f => FilesystemFile.FromFileInfo(f));
+
+ var dirs = contents
+ .OfType<DirectoryInfo>()
+ .Prepend(dir)
+ .Select(d => FilesystemDirectory.FromDirectoryInfo(d) with { Files = files.Where(f => f.Parent == d.FullName) });
+
+ return dirs;
+ });
}
private bool IsPermissibleDirectory(string dir, Options.DirectoriesOptions options)