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 issue in create_temporary_directory (affecting XMLValidator with schematron) #4961

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/utilities/core/FilesystemHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,14 @@ namespace filesystem {
}

openstudio::path create_temporary_directory(const openstudio::path& basename) {
// making this count static/atomic so that we reduce the chance of collisions
// on each run of the binary. This is threadsafe, with the atomic
static std::atomic<unsigned int> count = 0;
constexpr unsigned int allowed_attempts = 1000;

const auto base_temp_dir = openstudio::filesystem::temp_directory_path();
// std::filesystem::unique_path doesn't exist, if moving to std::filesystem, use emoveBraces(createUUID)
// std::filesystem::unique_path doesn't exist, if moving to std::filesystem, use removeBraces(createUUID())
auto upath = boost::filesystem::unique_path();
const auto temp_dir = base_temp_dir / fmt::format("{}-{}-{}-", basename.string(), upath.string(), std::time(nullptr));

// unique_path is supposed to be unique already...
unsigned int count = 0;
constexpr unsigned int allowed_attempts = 1000;
while (count < allowed_attempts) {
// concat number to path basename, without adding a new path element
auto full_pathname = temp_dir;
Expand Down