From dfa8e803fa7cd5eee275c8c67f29aebab439625a Mon Sep 17 00:00:00 2001 From: Erik Mavrinac Date: Mon, 5 Feb 2024 11:01:05 -0800 Subject: [PATCH] More code cleanup, merge interface implementations --- {Service => Lib}/DirectoryMetadata.cs | 11 +++++++---- {Service => Lib}/FileSystemEntry.cs | 10 ++++++---- Tests/DirectoryMetadata.cs | 26 -------------------------- Tests/FileSystemEntry.cs | 26 -------------------------- 4 files changed, 13 insertions(+), 60 deletions(-) rename {Service => Lib}/DirectoryMetadata.cs (68%) rename {Service => Lib}/FileSystemEntry.cs (73%) delete mode 100644 Tests/DirectoryMetadata.cs delete mode 100644 Tests/FileSystemEntry.cs diff --git a/Service/DirectoryMetadata.cs b/Lib/DirectoryMetadata.cs similarity index 68% rename from Service/DirectoryMetadata.cs rename to Lib/DirectoryMetadata.cs index 48f4d08..ee36907 100644 --- a/Service/DirectoryMetadata.cs +++ b/Lib/DirectoryMetadata.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; using System.Linq; -using WinVfs.VirtualFilesystem; -namespace WinVfs.Service; +namespace WinVfs.VirtualFilesystem; -internal sealed class DirectoryMetadata : IDirectoryMetadata +/// +/// Default implementation of with an O(N) lookup in +/// and a non-thread-safe writeable collection of entries. +/// +public sealed class DirectoryMetadata : IDirectoryMetadata { public DirectoryMetadata(string relativeBasePath, bool exists = true) { @@ -23,4 +26,4 @@ public DirectoryMetadata(string relativeBasePath, bool exists = true) { return WritableEntries.FirstOrDefault(e => e.Name.Equals(fileOrDirName, StringComparison.OrdinalIgnoreCase)); } -} \ No newline at end of file +} diff --git a/Service/FileSystemEntry.cs b/Lib/FileSystemEntry.cs similarity index 73% rename from Service/FileSystemEntry.cs rename to Lib/FileSystemEntry.cs index dd7fcf5..12be3fe 100644 --- a/Service/FileSystemEntry.cs +++ b/Lib/FileSystemEntry.cs @@ -1,9 +1,11 @@ using System; -using WinVfs.VirtualFilesystem; -namespace WinVfs.Service; +namespace WinVfs.VirtualFilesystem; -internal sealed class FileSystemEntry : IFileSystemEntry +/// +/// Default implementation of +/// +public sealed class FileSystemEntry : IFileSystemEntry { public FileSystemEntry(string dirName) { @@ -23,4 +25,4 @@ public FileSystemEntry(string fileName, long fileSize, DateTime? lastUpdateTimeU public long FileSize { get; } public string Name { get; } public DateTime? LastUpdateTimeUtc { get; } -} \ No newline at end of file +} diff --git a/Tests/DirectoryMetadata.cs b/Tests/DirectoryMetadata.cs deleted file mode 100644 index dd03912..0000000 --- a/Tests/DirectoryMetadata.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using WinVfs.VirtualFilesystem; - -namespace WinVfs.Tests; - -internal sealed class DirectoryMetadata : IDirectoryMetadata -{ - public DirectoryMetadata(string relativeBasePath, bool exists = true) - { - RelativeBasePath = relativeBasePath; - Exists = exists; - } - - public string RelativeBasePath { get; } - public bool Exists { get; } - - public List WritableEntries { get; } = new(); - public IReadOnlyList Entries => WritableEntries; - - public IFileSystemEntry? GetEntryOrNull(string fileOrDirName) - { - return WritableEntries.FirstOrDefault(e => e.Name.Equals(fileOrDirName, StringComparison.OrdinalIgnoreCase)); - } -} \ No newline at end of file diff --git a/Tests/FileSystemEntry.cs b/Tests/FileSystemEntry.cs deleted file mode 100644 index 61a4ab8..0000000 --- a/Tests/FileSystemEntry.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using WinVfs.VirtualFilesystem; - -namespace WinVfs.Tests; - -internal sealed class FileSystemEntry : IFileSystemEntry -{ - public FileSystemEntry(string dirName) - { - Name = dirName; - IsDirectory = true; - FileSize = -1; - } - - public FileSystemEntry(string fileName, long fileSize, DateTime? lastUpdateTimeUtc = null) - { - Name = fileName; - FileSize = fileSize; - LastUpdateTimeUtc = lastUpdateTimeUtc; - } - - public bool IsDirectory { get; } - public long FileSize { get; } - public string Name { get; } - public DateTime? LastUpdateTimeUtc { get; } -}