aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Files/FileService.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-06-21 08:54:04 -0500
committerJP Dillingham <jp@dillingham.me>2023-06-21 08:54:04 -0500
commit05bc0e09d54ff4a9e3924668c312610c221bd2b6 (patch)
treecc3549be4d4cb00c1a16c58a1a9a35ed909a8d8e /src/slskd/Files/FileService.cs
parent5e9c7f4a4ba0f20ded6133b763cf0d0132fb7caa (diff)
downloadslskd-05bc0e09d54ff4a9e3924668c312610c221bd2b6.tar.gz
simplify contents listing
Diffstat (limited to 'src/slskd/Files/FileService.cs')
-rw-r--r--src/slskd/Files/FileService.cs27
1 files changed, 7 insertions, 20 deletions
diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs
index a579bc79..c7c0105c 100644
--- a/src/slskd/Files/FileService.cs
+++ b/src/slskd/Files/FileService.cs
@@ -42,42 +42,29 @@ namespace slskd.Files
private IOptionsSnapshot<Options> OptionsSnapshot { get; }
/// <summary>
- /// Lists all of the directories in the specified <paramref name="parentDirectory"/>, optionally applying the
+ /// Lists all of the contents of 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>
/// <param name="enumerationOptions">Optional enumeration options to apply.</param>
- /// <returns>The list of found directories.</returns>
+ /// <returns>The list of found contents.</returns>
/// <exception cref="InvalidDirectoryException">
/// Thrown if the specified directory is not rooted in an allowed directory.
/// </exception>
- public async Task<IEnumerable<DirectoryInfo>> ListDirectoriesAsync(string parentDirectory, EnumerationOptions enumerationOptions = null)
+ /// <exception cref="NotFoundException">Thrown if the specified directory does not exist.</exception>
+ public async Task<IEnumerable<FileSystemInfo>> ListContentsAsync(string parentDirectory, EnumerationOptions enumerationOptions = null)
{
if (!IsPermissibleDirectory(parentDirectory, OptionsSnapshot.Value.Directories))
{
throw new InvalidDirectoryException($"The directory '{parentDirectory}' is not rooted in any of the allowed directories");
}
- return await Task.Run(() => new DirectoryInfo(parentDirectory).GetDirectories("*", enumerationOptions));
- }
-
- /// <summary>
- /// Lists all of the files in the specified <paramref name="parentDirectory"/>, optionally applying the specified <paramref name="enumerationOptions"/>.
- /// </summary>
- /// <param name="parentDirectory">An optional parent directory from which to begin searching.</param>
- /// <param name="enumerationOptions">Optional enumeration options to apply.</param>
- /// <returns>The list of found files.</returns>
- /// <exception cref="InvalidDirectoryException">
- /// Thrown if the specified directory is not rooted in an allowed directory.
- /// </exception>
- public async Task<IEnumerable<FileInfo>> ListFilesAsync(string parentDirectory, EnumerationOptions enumerationOptions = null)
- {
- if (!IsPermissibleDirectory(parentDirectory, OptionsSnapshot.Value.Directories))
+ if (!Directory.Exists(parentDirectory))
{
- throw new InvalidDirectoryException($"The directory '{parentDirectory}' is not rooted in any of the applowed directories");
+ throw new NotFoundException($"The directory '{parentDirectory}' does not exist");
}
- return await Task.Run(() => new DirectoryInfo(parentDirectory).GetFiles("*", enumerationOptions));
+ return await Task.Run(() => new DirectoryInfo(parentDirectory).GetFileSystemInfos("*", enumerationOptions));
}
private bool IsPermissibleDirectory(string dir, Options.DirectoriesOptions options)