From 05bc0e09d54ff4a9e3924668c312610c221bd2b6 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 21 Jun 2023 08:54:04 -0500 Subject: simplify contents listing --- src/slskd/Files/FileService.cs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'src/slskd/Files/FileService.cs') 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 OptionsSnapshot { get; } /// - /// Lists all of the directories in the specified , optionally applying the + /// Lists all of the contents of the specified , optionally applying the /// specified . /// /// The directory from which to start the listing. /// Optional enumeration options to apply. - /// The list of found directories. + /// The list of found contents. /// /// Thrown if the specified directory is not rooted in an allowed directory. /// - public async Task> ListDirectoriesAsync(string parentDirectory, EnumerationOptions enumerationOptions = null) + /// Thrown if the specified directory does not exist. + public async Task> 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)); - } - - /// - /// Lists all of the files in the specified , optionally applying the specified . - /// - /// An optional parent directory from which to begin searching. - /// Optional enumeration options to apply. - /// The list of found files. - /// - /// Thrown if the specified directory is not rooted in an allowed directory. - /// - public async Task> 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) -- cgit v1.2.3