-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add file size to DirectoryEntry #24176
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
60306a9
Add file size to DirectoryEntry
ravenblackx 2a19b95
Add test to validate size
ravenblackx 19c8a58
Fix tests
ravenblackx 9cc86ca
Fix mistaken const
ravenblackx 331c5af
makeEntry test needs to be filesystem-independent
ravenblackx 47323f2
Drop unused temps, clarify the final FileType case.
ravenblackx 78d3c79
TODO for not throwing exception.
ravenblackx 2a6b3ab
Assert success of test file operations
ravenblackx 6037bb9
Fix operator==, improve test output, simplify flow
ravenblackx 99a7632
ASSERT->EXPECT
ravenblackx 2ce171d
Windows style large integers without byte shuffling
ravenblackx 2eecbfc
*Unsigned* large integer
ravenblackx 4e840cd
Turn off linter for PrintTo
ravenblackx 5acaaf7
Allow indeterminate size for non-regular files; Windows has size-0 sy…
ravenblackx b582141
Merge remote-tracking branch 'upstream/main' into stat
ravenblackx ae4ae1f
Use `absl::nullopt` to indicate size unknown
ravenblackx 0257b05
Correct test comment that still said 0
ravenblackx de66291
Only get size when used, and fix grouping, for Win32
ravenblackx f11bd48
Add testing of DirectoryEntry == operator
ravenblackx 6c3d3b4
Merge remote-tracking branch 'upstream/main' into stat
ravenblackx 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
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -16,7 +16,7 @@ DirectoryIteratorImpl::DirectoryIteratorImpl(const std::string& directory_path) | |
fmt::format("unable to open directory {}: {}", directory_path, ::GetLastError())); | ||
} | ||
|
||
entry_ = {std::string(find_data.cFileName), fileType(find_data)}; | ||
entry_ = makeEntry(find_data); | ||
} | ||
|
||
DirectoryIteratorImpl::~DirectoryIteratorImpl() { | ||
|
@@ -34,27 +34,30 @@ DirectoryIteratorImpl& DirectoryIteratorImpl::operator++() { | |
} | ||
|
||
if (ret == 0) { | ||
entry_ = {"", FileType::Other}; | ||
entry_ = {"", FileType::Other, absl::nullopt}; | ||
} else { | ||
entry_ = {std::string(find_data.cFileName), fileType(find_data)}; | ||
entry_ = makeEntry(find_data); | ||
} | ||
|
||
return *this; | ||
} | ||
|
||
FileType DirectoryIteratorImpl::fileType(const WIN32_FIND_DATA& find_data) const { | ||
DirectoryEntry DirectoryIteratorImpl::makeEntry(const WIN32_FIND_DATA& find_data) { | ||
ULARGE_INTEGER file_size; | ||
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. should this all be in the final else? 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. Good call, now that it's unset everywhere else! |
||
file_size.LowPart = find_data.nFileSizeLow; | ||
file_size.HighPart = find_data.nFileSizeHigh; | ||
uint64_t size = static_cast<uint64_t>(file_size.QuadPart); | ||
if ((find_data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && | ||
!(find_data.dwReserved0 & IO_REPARSE_TAG_SYMLINK)) { | ||
// The file is reparse point and not a symlink, so it can't be | ||
// a regular file or a directory | ||
return FileType::Other; | ||
} | ||
|
||
if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { | ||
return FileType::Directory; | ||
return {std::string(find_data.cFileName), FileType::Other, absl::nullopt}; | ||
} else if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { | ||
return {std::string(find_data.cFileName), FileType::Directory, absl::nullopt}; | ||
} else { | ||
return {std::string(find_data.cFileName), FileType::Regular, | ||
(find_data.dwReserved0 & IO_REPARSE_TAG_SYMLINK) ? absl::nullopt : size}; | ||
} | ||
|
||
return FileType::Regular; | ||
} | ||
|
||
} // namespace Filesystem | ||
|
This file contains 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
Oops, something went wrong.
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.
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.
sorry if I'm missing but did we test this new equivalence?
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.
We did now.