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

Feature/remove yuni file separator #175

Open
wants to merge 3 commits into
base: New-Antares-Emulator-2
Choose a base branch
from
Open
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();
}

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