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

Use non-throwing std::filesystem functions in the type registry #1472

Merged
merged 2 commits into from
Mar 18, 2021

Conversation

tobim
Copy link
Member

@tobim tobim commented Mar 18, 2021

📔 Description

Change 2 use sites of exists().

📝 Checklist

  • All user-facing changes have changelog entries.

@tobim tobim added the bug Incorrect behavior label Mar 18, 2021
@tobim tobim requested a review from a team March 18, 2021 14:57
@@ -77,18 +77,23 @@ caf::error type_registry_state::save_to_disk() const {

caf::error type_registry_state::load_from_disk() {
// Nothing to load is not an error.
if (!exists(dir)) {
std::error_code err{};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this picked up via ADL? My goodness.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dir is of type std::filesystem::path, so what else would you expect?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No surprise we didn't catch this one during review.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta love ADL. 😒

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. Sorry I missed this when I introduced this change 😞

Thanks for the fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, these things happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of those things that are only obvious in hindsight. We probably would have run into the exact same issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pedantically, can you help me understand why exists unqualified would pick up std::filesystem::exists? I don't see us do a using namespace std; or anything like that. Who's bringing it into scope?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this recent article on (among other things) ADL: https://preshing.com/20210315/how-cpp-resolves-a-function-call/

Copy link
Member

@dominiklohmann dominiklohmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not test locally. This should be covered by CI. Did you verify that this fixes the issue with the systemd setup?

libvast/src/system/type_registry.cpp Outdated Show resolved Hide resolved
@tobim
Copy link
Member Author

tobim commented Mar 18, 2021

Did you verify that this fixes the issue with the systemd setup?

Not yet, I wanted to use the CI artifact for that.

@dominiklohmann
Copy link
Member

Not yet, I wanted to use the CI artifact for that.

Consider it approved if the issue is fixed ;)

@tobim tobim force-pushed the story/ch23539/filesystem-exception branch from c5f3dbc to 0b2da3b Compare March 18, 2021 15:06
@tobim
Copy link
Member Author

tobim commented Mar 18, 2021

It is indeed fixed.

@tobim tobim enabled auto-merge March 18, 2021 17:11
auto dirs = get_schema_dirs(self->system().config());
concepts_map concepts;
models_map models;
for (const auto& dir : dirs) {
if (!exists(dir))
auto dir_exists = std::filesystem::exists(dir, err);
if (err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do err.clear(). In the case where more than one directory doesn't exist (and since we continue in the loop), I think we want to warn on just the ones that don't exist rather than erroneously warn on all of the dirs remaining after the first one fails (and thus err is set). Does that make sense? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists() calls err.clear() itself if it didn't fail. See https://en.cppreference.com/w/cpp/filesystem/exists.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, perfect then. 👍

@tobim tobim force-pushed the story/ch23539/filesystem-exception branch from 0b2da3b to 0836774 Compare March 18, 2021 20:16
@tobim tobim merged commit 3c8009f into master Mar 18, 2021
@tobim tobim deleted the story/ch23539/filesystem-exception branch March 18, 2021 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants