From da88bbb819dfa4420c97c09a840748942bc7f081 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 11 Oct 2022 18:59:35 -0500 Subject: separate read/write interfaces --- src/slskd/Shares/ShareRepository.cs | 85 ++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/slskd/Shares/ShareRepository.cs b/src/slskd/Shares/ShareRepository.cs index 7b723ac6..fd69c2a3 100644 --- a/src/slskd/Shares/ShareRepository.cs +++ b/src/slskd/Shares/ShareRepository.cs @@ -26,15 +26,14 @@ namespace slskd.Shares using Soulseek; /// - /// Persistent storage of shared files and metadata. + /// Read-only persistent storage of shared files and metadata. /// - public interface IShareRepository + public interface IReadOnlyShareRepository { /// - /// Backs the current database up to the database at the specified . + /// Gets the connection string for this repository. /// - /// The connection string of the destination database. - void BackupTo(string connectionString); + string ConnectionString { get; } /// /// Counts the number of directories in the database. @@ -50,6 +49,41 @@ namespace slskd.Shares /// The number of files. int CountFiles(string parentDirectory = null); + /// + /// Finds the filename of the file matching the specified . + /// + /// The fully qualified remote path of the file. + /// The filename, if found. + string FindFilename(string maskedFilename); + + /// + /// Lists all directories. + /// + /// The optional directory prefix used for listing subdirectories. + /// The list of directories. + IEnumerable ListDirectories(string parentDirectory = null); + + /// + /// Lists all files. + /// + /// The optional parent directory. + /// A value indicating whether the fully qualified path should be returned. + /// The list of files. + IEnumerable ListFiles(string parentDirectory = null, bool includeFullPath = false); + + /// + /// Searches the database for files matching the specified . + /// + /// The search query. + /// The list of matching files. + IEnumerable Search(SearchQuery query); + } + + /// + /// Writeable persistent storage of shared files and metadata. + /// + public interface IShareRepository : IReadOnlyShareRepository + { /// /// Creates a new database. /// @@ -60,13 +94,6 @@ namespace slskd.Shares /// An optional value that determines whether the existing database should be discarded. void Create(bool discardExisting = false); - /// - /// Finds the filename of the file matching the specified . - /// - /// The fully qualified remote path of the file. - /// The filename, if found. - string FindFilename(string maskedFilename); - /// /// Inserts a directory. /// @@ -92,19 +119,16 @@ namespace slskd.Shares void InsertScan(long timestamp, Options.SharesOptions options); /// - /// Lists all directories. + /// Backs the current database up to the database at the specified . /// - /// The optional directory prefix used for listing subdirectories. - /// The list of directories. - IEnumerable ListDirectories(string parentDirectory = null); + /// The connection string of the destination database. + void BackupTo(string connectionString); /// - /// Lists all files. + /// Restores the current database from the database at the specified . /// - /// The optional parent directory. - /// A value indicating whether the fully qualified path should be returned. - /// The list of files. - IEnumerable ListFiles(string parentDirectory = null, bool includeFullPath = false); + /// The connection string of the source database. + void RestoreFrom(string connectionString); /// /// Deletes directory records with a timestamp prior to the specified . @@ -120,19 +144,6 @@ namespace slskd.Shares /// The number of records deleted. long PruneFiles(long olderThanTimestamp); - /// - /// Restores the current database from the database at the specified . - /// - /// The connection string of the source database. - void RestoreFrom(string connectionString); - - /// - /// Searches the database for files matching the specified . - /// - /// The search query. - /// The list of matching files. - IEnumerable Search(SearchQuery query); - /// /// Updates the scan started at the specified to set the . /// @@ -155,7 +166,11 @@ namespace slskd.Shares ConnectionString = connectionString; } - private string ConnectionString { get; } + /// + /// Gets the connection string for this repository. + /// + public string ConnectionString { get; } + private ILogger Log { get; } = Serilog.Log.ForContext(); /// -- cgit v1.2.3