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

Implement proper handling of dirent in FormulationManager, fixes #517 #518

Merged

Conversation

hellkite500
Copy link
Member

Fixes a bug that prevents forcing files from being properly discovered/validated on certain systems/file-systems.

Changes

  • Refactor directory iteration to fallback to stat when appropriate.

Testing

  1. All unit tests tested locall

Todos

  • Should check any other places in the code potentially using dirent and readdir for similar issues.

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Target Environment support

  • Linux
  • MacOS

}
else if ( entry->d_type == DT_UNKNOWN )
#endif
{
Copy link
Contributor

Choose a reason for hiding this comment

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

This is throwing me off - if the _DIRENT_HAVE_D_TYPE condition doesn't pass, does this yield:

if( match ) {
    {
        struct stat st;
        if( stat((path+entry->d_name)>c_str(), &st) != 0) {...
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it might be a little easier to see from this SS where the IDE does some nice high/low lighting

image

Copy link
Contributor

@donaldwj donaldwj left a comment

Choose a reason for hiding this comment

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

Where is _DIRENT_HAVE_D_TYPE defined and is it a gcc extension? Ie will this work with intel compilers

Copy link
Contributor

@donaldwj donaldwj left a comment

Choose a reason for hiding this comment

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

So it looks like type information can also be present with the preprocessor directives of _DEFAULT_SOURCE glibc > 2.19 or _BSD_SOURCE for earlier library versions. Even in this case the d_type could be set to unknown based on the file system being read.

@hellkite500
Copy link
Member Author

Where is _DIRENT_HAVE_D_TYPE defined and is it a gcc extension? Ie will this work with intel compilers

This is in dirent.h (see the documentation about the additional fields.)

@hellkite500
Copy link
Member Author

So it looks like type information can also be present with the preprocessor directives of _DEFAULT_SOURCE glibc > 2.19 or _BSD_SOURCE for earlier library versions. Even in this case the d_type could be set to unknown based on the file system being read.

I think the fallback to stat.h is sufficient in either case. I don't think the _DIRENT_HAVE_D_TYPE is gcc specific, but is GNU system specific. It may be that the macro isn't defined on all systems that are actually capable of providing d_type from a dirent struct, but then we can just fall back to stat and be covered on any POSIX system.

@hellkite500 hellkite500 merged commit f2725df into NOAA-OWP:master Apr 27, 2023
@hellkite500 hellkite500 deleted the fix-forcing-discovery-logic branch April 27, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A few portability issues with the use of dirent for validating forcing file paths in model engine.
3 participants