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

remove unuseful yuni string separator #1788

Closed
wants to merge 3 commits into from
Closed
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
34 changes: 29 additions & 5 deletions src/solver/utils/ortools_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <antares/exception/AssertionError.hpp>
#include <antares/Enum.hpp>
#include <filesystem>
#ifdef _WIN32
#include <io.h>
#endif

using namespace operations_research;

Expand Down Expand Up @@ -212,14 +215,35 @@ static void extract_from_MPSolver(MPSolver* solver,
}
}

std::filesystem::path CreateRandomSubDir(const std::filesystem::path& parentDir)
{
char template_array[] = "XXXXXX";
#ifdef __linux__
auto template_dir = parentDir / template_array;
char* template_dir_array = template_dir.string().data();
if (auto ret = mkdtemp(template_dir_array); ret != nullptr)
{
return ret;
}
#elif _WIN32
if (auto ret = _mktemp_s(template_array); ret == 0)
{
auto created_dir = parentDir / template_array;
std::filesystem::create_directory(created_dir);
return created_dir;
}
#endif
else
{
Antares::logs.warning() << "Could not create random subdirectory in " << parentDir.string()
<< "\n";
return parentDir;
}
}
std::string generateTempPath(const std::string& filename)
{
namespace fs = std::filesystem;
std::ostringstream tmpPath;
tmpPath << fs::temp_directory_path().string() << Yuni::IO::SeparatorAsString << filename;
return tmpPath.str();
return (CreateRandomSubDir(std::filesystem::temp_directory_path()) / filename).string().c_str();
Comment on lines -218 to +245
Copy link
Member

Choose a reason for hiding this comment

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

This changes the behavior. How about keeping the same behavior as previously ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see Pr reviews

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and we may remove the last 2 commits

}

void removeTemporaryFile(const std::string& tmpPath)
{
namespace fs = std::filesystem;
Expand Down