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

Fix #4761 - Cleanup temporary directory when doing *Schematron* XMLValidation #4762

Merged
merged 3 commits into from Dec 13, 2022

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Dec 10, 2022

Pull request overview

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@jmarrec jmarrec added severity - Minor Bug component - Utilities Other Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. labels Dec 10, 2022
@jmarrec jmarrec self-assigned this Dec 10, 2022
Comment on lines +167 to +168
// #4761 - XMLValidator's dtor should clean up the tmpDir
EXPECT_FALSE(openstudio::filesystem::exists(tmpDir)) << "Expected tmpDir to be deleted: " << tmpDir;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fails before fix, works after

const auto tmpDir = openstudio::filesystem::create_temporary_directory("xmlvalidation");
if (tmpDir.empty()) {
LOG_AND_THROW(fmt::format("Failed to create a temporary directory for extracting the stylesheets need to transform the Schematron '{}'",
m_tempDir = openstudio::filesystem::create_temporary_directory("xmlvalidation");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

store the temp dir

Comment on lines +215 to +224
XMLValidator::~XMLValidator() {
if (m_tempDir) {
try {
const auto count = openstudio::filesystem::remove_all(m_tempDir.get());
logAndStore(Debug, fmt::format("Removed temporary directory with {} files", count));
} catch (const std::exception& e) {
logAndStore(Warn, fmt::format("Error removing temporary directory at {}, Description: {}", toString(m_tempDir.get()), e.what()));
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Delete temp Dir in dtor

Comment on lines +71 to +75
~XMLValidator();
XMLValidator(const XMLValidator& other) = default;
XMLValidator(XMLValidator&& other) noexcept = default;
XMLValidator& operator=(const XMLValidator& other) = default;
XMLValidator& operator=(XMLValidator&& other) noexcept = default;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rule of 5

Copy link
Contributor

@shorowit shorowit left a comment

Choose a reason for hiding this comment

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

Haven't reviewed the code, but tried it out and confirmed that it cleaned up the temp dir in an OpenStudio-HPXML run. Thanks @jmarrec!

@tijcolem
Copy link
Collaborator

@jmarrec This looks great. Thank for fixing so quickly for @shorowit. We can get this into 3.5.1 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component - Utilities Other Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. severity - Minor Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XML validation doesn't clean up after itself
4 participants