Use os.Stat to check for file instead of os.Open#338
Open
willbeason wants to merge 1 commit intogoogle:masterfrom
Open
Use os.Stat to check for file instead of os.Open#338willbeason wants to merge 1 commit intogoogle:masterfrom
willbeason wants to merge 1 commit intogoogle:masterfrom
Conversation
The code for save previously used os.Open to check if the directory to write to with save already exists. This commit changes to use os.Stat instead, which can perform the equivalent verification. This is cleaner since we don't end up with a file we then need to close. Added an E2E test to verify this works, but I'm happy to delete if this seems like overkill. I tried to mimic the style of the existing tests. While writing this test I made some small improvements to the existing tests: 1. Moved to using t.TempDir (which does automatic cleanup) for temporary directories instead of os.MkDirTemp. 2. Replaced the direct casts to ExitError with the more modern errors.As.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The code for save previously used os.Open to check if the directory to write to with save already exists. This commit changes to use os.Stat instead, which can perform the equivalent verification.
This is cleaner since we don't end up with a file we then need to close.
Added an E2E test to verify this works, but I'm happy to delete if this seems like overkill. I tried to mimic the style of the existing tests.
While writing this test I made some small improvements to the existing tests:
Moved to using t.TempDir (which does automatic cleanup) for temporary directories instead of os.MkDirTemp.
Replaced the direct casts to ExitError with the more modern errors.As.