mem: return error when reading a directory (fixes #430)#597
Open
nghiack7 wants to merge 1 commit into
Open
Conversation
ReadAt on a MemMapFs file backed by a directory now returns
os.PathError{Err: "is a directory"}, matching the behaviour of
the real OS filesystem. Previously it silently returned 0 bytes
and no error, causing afero.ReadFile(fs, dirPath) to succeed and
return empty content.
Fixes spf13#430
00da920 to
81d5b57
Compare
Author
|
@CLAassistant recheck |
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.
Summary
afero.ReadFile(fs, dirPath)on aMemMapFssilently returned empty content with anilerror. The real OS filesystem returns an error (read /some/dir: is a directory). This inconsistency was reported in #430.Root cause
(*File).Readdelegates toReadAt, which had no guard for directory-backed files. It would simply returnn=0, err=nilbecause the file data slice is empty for directories.Fix
Added a directory check at the top of
ReadAt:Readalready delegates toReadAt, so both are covered by one guard.Test
Added
TestReadFileOnDirectoryinutil_test.gothat:MemMapFsdirectoryafero.ReadFileon itFull test suite passes without regressions.
Fixes #430