-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
fix: Simplified IFileSystem
#3641
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
namespace Sentry.Internal; | ||
|
||
internal enum FileOperationResult | ||
{ | ||
Success, | ||
Failure, | ||
Disabled | ||
} | ||
|
||
internal interface IFileSystem | ||
{ | ||
// Note: You are responsible for handling success/failure when attempting to write to disk. | ||
// You are required to check for `Options.FileWriteDisabled` whether you are allowed to call any writing operations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good call out. Adding a sexton like or (can't recall the options) above methods in the interface with a snippet might make it even more obvious |
||
// The options will automatically pick between `ReadOnly` and `ReadAndWrite` to prevent accidental file writing that | ||
// could cause crashes on restricted platforms like the Nintendo Switch. | ||
|
||
// Note: This is not comprehensive. If you need other filesystem methods, add to this interface, | ||
// then implement in both Sentry.Internal.FileSystem and Sentry.Testing.FakeFileSystem. | ||
|
||
|
@@ -21,10 +19,10 @@ internal interface IFileSystem | |
string? ReadAllTextFromFile(string file); | ||
Stream OpenFileForReading(string path); | ||
|
||
FileOperationResult CreateDirectory(string path); | ||
FileOperationResult DeleteDirectory(string path, bool recursive = false); | ||
FileOperationResult CreateFileForWriting(string path, out Stream fileStream); | ||
FileOperationResult WriteAllTextToFile(string path, string contents); | ||
FileOperationResult MoveFile(string sourceFileName, string destFileName, bool overwrite = false); | ||
FileOperationResult DeleteFile(string path); | ||
bool CreateDirectory(string path); | ||
bool DeleteDirectory(string path, bool recursive = false); | ||
bool CreateFileForWriting(string path, out Stream fileStream); | ||
bool WriteAllTextToFile(string path, string contents); | ||
bool MoveFile(string sourceFileName, string destFileName, bool overwrite = false); | ||
bool DeleteFile(string path); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,24 @@ namespace Sentry.Internal; | |
|
||
internal class ReadOnlyFileSystem : FileSystemBase | ||
{ | ||
public override FileOperationResult CreateDirectory(string path) => FileOperationResult.Disabled; | ||
// Note: You are responsible for handling success/failure when attempting to write to disk. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this won't show up in the IDE at call site. Needs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These interfaces and classes are all internal, so it looks like the only place to document this is in some remarks or something on |
||
// You are required to check for `Options.FileWriteDisabled` whether you are allowed to call any writing operations. | ||
// The options will automatically pick between `ReadOnly` and `ReadAndWrite` to prevent accidental file writing that | ||
// could cause crashes on restricted platforms like the Nintendo Switch. | ||
|
||
public override FileOperationResult DeleteDirectory(string path, bool recursive = false) => FileOperationResult.Disabled; | ||
public override bool CreateDirectory(string path) => false; | ||
|
||
public override FileOperationResult CreateFileForWriting(string path, out Stream fileStream) | ||
public override bool DeleteDirectory(string path, bool recursive = false) => false; | ||
|
||
public override bool CreateFileForWriting(string path, out Stream fileStream) | ||
{ | ||
fileStream = Stream.Null; | ||
return FileOperationResult.Disabled; | ||
return false; | ||
} | ||
|
||
public override FileOperationResult WriteAllTextToFile(string path, string contents) => FileOperationResult.Disabled; | ||
public override bool WriteAllTextToFile(string path, string contents) => false; | ||
|
||
public override FileOperationResult MoveFile(string sourceFileName, string destFileName, bool overwrite = false) => | ||
FileOperationResult.Disabled; | ||
public override bool MoveFile(string sourceFileName, string destFileName, bool overwrite = false) => false; | ||
|
||
public override FileOperationResult DeleteFile(string path) => FileOperationResult.Disabled; | ||
public override bool DeleteFile(string path) => false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used once in the
GlobalSessionsManager
. Success/Failure is getting handled there and does not need to be abstracted away into an extension.