Skip to content
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 20 commits into from
Dec 7, 2022
Merged

Add file size to DirectoryEntry #24176

merged 20 commits into from
Dec 7, 2022

Conversation

ravenblackx
Copy link
Contributor

@ravenblackx ravenblackx commented Nov 23, 2022

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 to stat 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.

Signed-off-by: Raven Black <ravenblack@dropbox.com>
@repokitteh-read-only
Copy link

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #24176 was opened by ravenblackx.

see: more, trace.

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>
@ravenblackx
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #24176 (comment) was created by @ravenblackx.

see: more, trace.

@ravenblackx ravenblackx marked this pull request as ready for review November 24, 2022 03:18
@jmarantz jmarantz self-assigned this Nov 25, 2022
Copy link
Contributor

@jmarantz jmarantz left a 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.

envoy/filesystem/filesystem.h Outdated Show resolved Hide resolved
source/common/filesystem/posix/directory_iterator_impl.cc Outdated Show resolved Hide resolved
source/common/filesystem/posix/directory_iterator_impl.cc Outdated Show resolved Hide resolved
test/common/filesystem/directory_test.cc Show resolved Hide resolved
@jmarantz
Copy link
Contributor

/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>
Copy link
Contributor

@jmarantz jmarantz left a 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.

envoy/filesystem/filesystem.h Outdated Show resolved Hide resolved
test/common/filesystem/directory_test.cc Show resolved Hide resolved
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>
@ravenblackx
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Check envoy-presubmit didn't fail.

🐱

Caused by: a #24176 (comment) was created by @ravenblackx.

see: more, trace.

jmarantz
jmarantz previously approved these changes Nov 30, 2022
Copy link
Contributor

@jmarantz jmarantz left a 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

@repokitteh-read-only
Copy link

envoyproxy/senior-maintainers assignee is @snowp

🐱

Caused by: a #24176 (review) was submitted by @jmarantz.

see: more, trace.

…mlinks, Linux has actual file size symlinks.

Signed-off-by: Raven Black <ravenblack@dropbox.com>
@ravenblackx
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #24176 (comment) was created by @ravenblackx.

see: more, trace.

(Maybe fix unrelated test failures.)

Signed-off-by: Raven Black <ravenblack@dropbox.com>
jmarantz
jmarantz previously approved these changes Dec 2, 2022
envoy/filesystem/filesystem.h Outdated Show resolved Hide resolved
@ravenblackx
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Check envoy-presubmit didn't fail.

🐱

Caused by: a #24176 (comment) was created by @ravenblackx.

see: more, trace.

@jmarantz jmarantz assigned alyssawilk and unassigned snowp Dec 5, 2022
snowp
snowp previously requested changes Dec 5, 2022
Copy link
Contributor

@snowp snowp left a 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

Comment on lines 172 to 174
// The file size in bytes for regular files. Should not be relied on for directories,
// symlinks, or FileType::Other.
uint64_t size_bytes_;
Copy link
Contributor

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?

Copy link
Contributor Author

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>
Copy link
Contributor

@alyssawilk alyssawilk left a 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;
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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";
Copy link
Contributor

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?

Copy link
Contributor Author

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_;
Copy link
Contributor

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?

Copy link
Contributor Author

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>
@alyssawilk alyssawilk enabled auto-merge (squash) December 6, 2022 22:00
@alyssawilk alyssawilk merged commit 75d06fb into envoyproxy:main Dec 7, 2022
jpsim added a commit that referenced this pull request Dec 7, 2022
….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>
jpsim added a commit that referenced this pull request Dec 8, 2022
…-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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants