Repository navigation
Add FileSystem Storage Provider - #78
Conversation
Implemented FileSystemStorageProvider with DI, config, and JSON support under src/StorageProviders.FileSystem. Added sample ASP.NET Core project demonstrating usage. Updated README with docs, added solution/project files, versioning, and GitHub Actions workflow for publishing. Included Capanno.jpg and minor sample improvements.
README.md reorganized for clarity: File System section moved before Azure Storage, with new badges, install steps, DI registration, and detailed usage/security notes. Azure Storage docs restructured for consistency, with clearer headings, install/usage instructions, and more code samples. Expanded metadata and provider behavior explanations. Improves onboarding and discoverability for both providers.
There was a problem hiding this comment.
🟡 Changes recommended
The new file-system provider has confirmed contract/security issues (missing-object reads throw instead of returning null, file URI creation can be relative on Unix, and internal metadata I/O lacks reparse-point validation).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR introduces a new local file-system backed IStorageProvider implementation, wires it into the solution and packaging workflow, and documents/illustrates its usage via a new sample and README updates.
Changes:
- Added
StorageProviders.FileSystemlibrary (provider + DI extensions + settings + source-gen JSON metadata support). - Added
FileSystemSampleASP.NET Core minimal API sample demonstrating file operations and metadata. - Updated solution, README, and GitHub Actions workflow to build/publish the new provider.
File summaries
| File | Description |
|---|---|
| StorageProviders.slnx | Adds the new provider and sample projects to the solution. |
| src/StorageProviders.FileSystem/version.json | Sets up NerdBank.GitVersioning for the new package. |
| src/StorageProviders.FileSystem/StorageProviders.FileSystem.xml | Adds generated XML doc output for the new assembly. |
| src/StorageProviders.FileSystem/StorageProviders.FileSystem.csproj | Defines multi-targeting and packaging metadata for the new provider. |
| src/StorageProviders.FileSystem/FileSystemStorageSettings.cs | Introduces the settings object (root directory). |
| src/StorageProviders.FileSystem/FileSystemStorageProviderExtensions.cs | Adds DI registration entry points for the new provider. |
| src/StorageProviders.FileSystem/FileSystemStorageProvider.cs | Implements file-system storage operations + metadata sidecars. |
| src/StorageProviders.FileSystem/FileSystemJsonSerializerContext.cs | Adds source-generated JSON serialization for metadata. |
| samples/FileSystemSample/Program.cs | Demonstrates API usage via minimal endpoints. |
| samples/FileSystemSample/Models/UploadFileWithMetadataRequest.cs | Defines the multipart upload + metadata request model. |
| samples/FileSystemSample/FileSystemSample.csproj | Adds a runnable sample referencing the new provider project. |
| samples/FileSystemSample/* (appsettings, http, launchSettings) | Provides configuration and request examples for the sample. |
| samples/AzureStorageSample/Program.cs | Adjusts Swagger UI mapping call style for consistency. |
| README.md | Documents the new provider (installation, registration, behavior, usage). |
| .github/workflows/publish_filesystem.yml | Adds NuGet publishing workflow for the new provider package. |
Review details
Files not reviewed (1)
- src/StorageProviders.FileSystem/StorageProviders.FileSystem.xml: Generated file
Suppressed comments (2)
src/StorageProviders.FileSystem/FileSystemStorageProvider.cs:256
WriteMetadataAsyncwrites tometadataPathwithout validating that the target path doesn't contain reparse points. This should apply the same reparse-point checks as the main file I/O to keep the storage root as the security boundary.
Directory.CreateDirectory(metadataDirectory);
await using var stream = new FileStream(metadataPath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, FileOptions.Asynchronous);
await JsonSerializer.SerializeAsync(stream, new FileSystemMetadata(metadata), FileSystemJsonSerializerContext.Default.FileSystemMetadata, cancellationToken).ConfigureAwait(false);
src/StorageProviders.FileSystem/FileSystemStorageProvider.cs:263
DeleteMetadatadeletes the sidecar JSON without any reparse-point validation. If.storageproviders/metadatawere replaced with a symlink, this could delete arbitrary files outside the storage root.
private void DeleteMetadata(string path)
{
if (Directory.Exists(metadataDirectory))
{
File.Delete(GetMetadataPath(path));
- Files reviewed: 17/19 changed files
- Comments generated: 5
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| rootDirectory = Path.GetFullPath(settings.RootDirectory); | ||
| metadataDirectory = Path.Combine(rootDirectory, ProviderDirectoryName, MetadataDirectoryName); | ||
|
|
||
| Directory.CreateDirectory(rootDirectory); | ||
| } |
| private async Task<IDictionary<string, string?>> ReadMetadataAsync(string path, CancellationToken cancellationToken) | ||
| { | ||
| var metadataPath = GetMetadataPath(path); | ||
| if (!File.Exists(metadataPath)) | ||
| { | ||
| return new FileSystemMetadata(); | ||
|
|
||
| } | ||
|
|
||
| await using var stream = new FileStream(metadataPath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, FileOptions.Asynchronous | FileOptions.SequentialScan); |
| public Task<Stream?> ReadAsStreamAsync(string path, CancellationToken cancellationToken = default) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
| var fullPath = GetExistingFilePath(path); | ||
|
|
||
| var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 81920, FileOptions.Asynchronous | FileOptions.SequentialScan); | ||
| return Task.FromResult<Stream?>(stream); | ||
| } |
| foreach (var filePath in Directory.EnumerateFiles(rootDirectory, "*", enumerationOptions)) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
| var logicalPath = Path.GetRelativePath(rootDirectory, filePath).Replace(Path.DirectorySeparatorChar, '/'); | ||
| if (logicalPath.StartsWith($"{ProviderDirectoryName}/", StringComparison.OrdinalIgnoreCase) || (normalizedPrefix is not null && !logicalPath.StartsWith(normalizedPrefix, GetPathComparison())) | ||
| || (extensionSet.Count > 0 && !extensionSet.Contains(Path.GetExtension(filePath)))) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| yield return logicalPath; | ||
| await Task.Yield(); | ||
| } |
| public Task<Uri> GetFullPathAsync(string path, CancellationToken cancellationToken = default) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
| var fullPath = GetFullPath(path); | ||
| EnsureNoReparsePoints(fullPath); | ||
|
|
||
| return Task.FromResult(new Uri(fullPath)); | ||
| } |
No description provided.