-
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
Conversation
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
/retest |
Retrying Azure Pipelines: |
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.
lgtm with a few nits.
/wait |
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
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.
lgtm modulo minor remaining nits.
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
/retest |
Retrying Azure Pipelines: |
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.
/assign-from envoyproxy/senior-maintainers
envoyproxy/senior-maintainers assignee is @snowp |
…mlinks, Linux has actual file size symlinks. Signed-off-by: Raven Black <ravenblack@dropbox.com>
/retest |
Retrying Azure Pipelines: |
(Maybe fix unrelated test failures.) Signed-off-by: Raven Black <ravenblack@dropbox.com>
/retest |
Retrying Azure Pipelines: |
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.
Overall lgtm, just one suggestion
envoy/filesystem/filesystem.h
Outdated
// The file size in bytes for regular files. Should not be relied on for directories, | ||
// symlinks, or FileType::Other. | ||
uint64_t size_bytes_; |
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.
Any way we can make this less of a footgun? One thing that comes to mind is wrapping it in a call that ASSERTs that type_
is Regular
? Or perhaps making it a absl::optional?
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.
Asserting that type_
is Regular
doesn't actually solve the problem, because on Windows with a symlink the type is regular and the size is unknown (or maybe it's the size of the linked path, I forget - either way, not the size of the file).
Using absl::optional
is a good idea though, to make it a hard failure instead of a quiet failure if size is used when it shouldn't be.
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
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.
Looks good overall!
/wait
} | ||
|
||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, now that it's unset everywhere else!
@@ -15,6 +15,17 @@ | |||
namespace Envoy { | |||
namespace Filesystem { | |||
|
|||
// NOLINTNEXTLINE(readability-identifier-naming) | |||
void PrintTo(const DirectoryEntry& entry, std::ostream* os) { |
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 something obvious but why NOLINTNEXTLINE? Can you not just have Envoy standard naming?
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.
PrintTo is a weird template override for test output of objects, so it's stuck using Google conventions. (If it was printTo then it wouldn't override.)
EXPECT_TRUE(file) << "failed to open test file"; | ||
file << contents; | ||
file.close(); | ||
EXPECT_TRUE(file) << "failed to write to test file"; |
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 ignorance of ostream but if you fail to write will file become null/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.
It becomes "falsy", because it overrides the bool-cast operator. Can't be null or false, because it's not a pointer.
bool operator==(const DirectoryEntry& rhs) const { | ||
return name_ == rhs.name_ && type_ == rhs.type_; | ||
return name_ == rhs.name_ && type_ == rhs.type_ && size_bytes_ == rhs.size_bytes_; |
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.
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
….h-into-multiple-header-files * origin/main: Add setRequestDecoder to ResponseEncoder interface (#24368) downstream: refactoring code to remove listener hard deps (#24394) lb api: moving load balancing policy specific configuration to extension configuration (#23967) ci: Skip docker/examples verification for docs or mobile only changes (#24417) ci: run mobile GitHub Actions on every PR (#24407) mobile: remove `bump_lyft_support_rotation.sh` script (#24404) Add file size to DirectoryEntry (#24176) bazel: update to 6.0.0rc4 (#24235) bazel: update rules_rust (#24409) Ecds config dump recommit (#24384) bazel: add another config_setting incompatible flag (#24270) listeners: moving listeners to extension directory (#24248) mobile: build Swift with whole module optimization (#24396) ci: update `actions/setup-java` from v1 to v3.8 (#24393) Signed-off-by: JP Simard <jp@jpsim.com>
…-cpp-to-latest-version * origin/main: (23 commits) Reduce Route memory utilization by avoiding RuntimeData instances when not needed (#24327) build: fix compile error for mac (#24429) postgres: support for upstream SSL (#23990) iOS: split `EnvoyEngine.h` into multiple header files (#24397) mobile: check for pending exceptions after JNI call (#24361) Remove uneccessary `this->` from mobile engine builder (#24389) Add setRequestDecoder to ResponseEncoder interface (#24368) downstream: refactoring code to remove listener hard deps (#24394) lb api: moving load balancing policy specific configuration to extension configuration (#23967) ci: Skip docker/examples verification for docs or mobile only changes (#24417) ci: run mobile GitHub Actions on every PR (#24407) mobile: remove `bump_lyft_support_rotation.sh` script (#24404) Add file size to DirectoryEntry (#24176) bazel: update to 6.0.0rc4 (#24235) bazel: update rules_rust (#24409) Ecds config dump recommit (#24384) bazel: add another config_setting incompatible flag (#24270) listeners: moving listeners to extension directory (#24248) mobile: build Swift with whole module optimization (#24396) ci: update `actions/setup-java` from v1 to v3.8 (#24393) ... Signed-off-by: JP Simard <jp@jpsim.com>
Commit Message: Add file size to DirectoryEntry
Additional Description: Directory [find] iterator is potentially useful for file system cache and, in future, serving content directly from file system. The iterator already has access to file size from
stat()
or its Windows equivalent, but it is not accessible to the caller. Using the current available APIs, the caller would have to make an additional call tostat
for each file they wish to know the size of. This change exposes the file size through the existing API, sparing those additional OS calls in the case that the size is useful, at the cost of a small value-copy.In passing, fixes a mistaken use of
errno
that should have been the error number from the os-call's returned structure, and updates a throw-test to not require a nominally private function to be public.Risk Level: Low. Simple change, existing fields should be unchanged.
Testing: Tests updated to match new values, one test added to validate that file size is returned.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: Updated both win32 and posix versions.