-
-
Notifications
You must be signed in to change notification settings - Fork 226
fix: Route file writing through FileSystem
#3614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b2f3283
make use of 'filesystem'
bitsandfoxes ab7c7e8
Apply suggestions from code review
bitsandfoxes eea1450
loggign
bitsandfoxes 3cfce14
use filesystem everywhere
bitsandfoxes 967e006
fix tests to use fakefilesystem
bitsandfoxes cdde5d5
verify
bitsandfoxes ba1df68
debug instead of warning
bitsandfoxes 21ac35b
make it work
bitsandfoxes 12c604d
Updated CHANGELOG.md
bitsandfoxes 561903e
comment
bitsandfoxes 9f77eb7
kiss
bitsandfoxes c3ebbab
restored sample
bitsandfoxes 4da424a
make filesystem smarter
bitsandfoxes 9ae1583
split filesystem
bitsandfoxes 2803559
finished split
bitsandfoxes 88d63f0
Merge branch 'main' into fix/filesystem
bitsandfoxes aa39e58
Format code
getsentry-bot 5aba1d2
logs
bitsandfoxes e318e89
Updated CHANGELOG.md
bitsandfoxes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
kiss
- Loading branch information
commit 9f77eb7580a169ed432053eed4d13d2a631c3dac
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| using Sentry.Extensibility; | ||
|
|
||
| namespace Sentry.Internal; | ||
|
|
||
| internal class FileSystem : IFileSystem | ||
| { | ||
| private readonly SentryOptions? _options; | ||
|
|
||
| public FileSystem(SentryOptions? options) | ||
| { | ||
| _options = options; | ||
| } | ||
|
|
||
| public IEnumerable<string> EnumerateFiles(string path) => Directory.EnumerateFiles(path); | ||
|
|
||
| public IEnumerable<string> EnumerateFiles(string path, string searchPattern) => | ||
| Directory.EnumerateFiles(path, searchPattern); | ||
|
|
||
| public IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOption) => | ||
| Directory.EnumerateFiles(path, searchPattern, searchOption); | ||
|
|
||
| public bool CreateDirectory(string path) | ||
| { | ||
| if (!_options?.DisableFileWrite is false) | ||
| { | ||
| _options?.LogDebug("Skipping creating directory. Writing to file system has been explicitly disabled."); | ||
| return false; | ||
| } | ||
|
|
||
| Directory.CreateDirectory(path); | ||
| return true; | ||
| } | ||
|
|
||
| public bool DeleteDirectory(string path, bool recursive = false) | ||
| { | ||
| if (!_options?.DisableFileWrite is false) | ||
bitsandfoxes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| _options?.LogDebug("Skipping deleting directory. Writing to file system has been explicitly disabled."); | ||
| return false; | ||
| } | ||
|
|
||
| Directory.Delete(path, recursive); | ||
| return true; | ||
| } | ||
|
|
||
| public bool DirectoryExists(string path) => Directory.Exists(path); | ||
|
|
||
| public bool FileExists(string path) => File.Exists(path); | ||
|
|
||
| public bool MoveFile(string sourceFileName, string destFileName, bool overwrite = false) | ||
| { | ||
| if (!_options?.DisableFileWrite is false) | ||
bitsandfoxes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| _options?.LogDebug("Skipping moving file. Writing to file system has been explicitly disabled."); | ||
| return false; | ||
| } | ||
|
|
||
| #if NETCOREAPP3_0_OR_GREATER | ||
| File.Move(sourceFileName, destFileName, overwrite); | ||
| #else | ||
| if (overwrite) | ||
| { | ||
| File.Copy(sourceFileName, destFileName, overwrite: true); | ||
| File.Delete(sourceFileName); | ||
| } | ||
| else | ||
| { | ||
| File.Move(sourceFileName, destFileName); | ||
| } | ||
| #endif | ||
| return true; | ||
| } | ||
|
|
||
| public bool DeleteFile(string path) | ||
| { | ||
| if (!_options?.DisableFileWrite is false) | ||
bitsandfoxes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| _options?.LogDebug("Skipping deleting file. Writing to file system has been explicitly disabled."); | ||
| return false; | ||
| } | ||
|
|
||
| File.Delete(path); | ||
| return true; | ||
| } | ||
|
|
||
| public DateTimeOffset GetFileCreationTime(string path) => new FileInfo(path).CreationTimeUtc; | ||
|
|
||
| public string ReadAllTextFromFile(string path) => File.ReadAllText(path); | ||
|
|
||
| public Stream OpenFileForReading(string path) => File.OpenRead(path); | ||
|
|
||
| public Stream CreateFileForWriting(string path) | ||
| { | ||
| if (!_options?.DisableFileWrite is false) | ||
| { | ||
| _options?.LogDebug("Skipping file for writing. Writing to file system has been explicitly disabled."); | ||
| return Stream.Null; | ||
| } | ||
|
|
||
| return File.Create(path); | ||
| } | ||
|
|
||
| public bool WriteAllTextToFile(string path, string contents) | ||
| { | ||
| if (!_options?.DisableFileWrite is false) | ||
| { | ||
| _options?.LogDebug("Skipping writing all text to file. Writing to file system has been explicitly disabled."); | ||
| return false; | ||
| } | ||
|
|
||
| File.WriteAllText(path, contents); | ||
| return true; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Sentry/Internal/ISentryFileSystem.cs → src/Sentry/Internal/IFileSystem.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
src/Sentry/Internal/SentryFileSystem.cs → test/Sentry.Testing/FakeFileSystem.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/Sentry.Tests/SentryFileSystemTests.cs → test/Sentry.Tests/FileSystemTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.