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

Cleanup the filesystem package #1043

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
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
98 changes: 42 additions & 56 deletions src/OMSimulatorLib/OMSFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,61 +43,8 @@ extern "C"
#endif
#endif

#if OMC_STD_FS == 1
// We have C++17; it has temp_directory_path and canonical
filesystem::path oms_temp_directory_path(void)
{
return filesystem::temp_directory_path();
}

filesystem::path oms_canonical(filesystem::path p)
{
return filesystem::canonical(p);
}
#else

#if !defined(OMC_STD_FS)
#include <cstdlib>

#if (BOOST_VERSION >= 104600) // no temp_directory_path in boost < 1.46
filesystem::path oms_temp_directory_path(void) {
return filesystem::temp_directory_path();
}
filesystem::path oms_canonical(filesystem::path p) {
return filesystem::canonical(p);
}
#else
filesystem::path oms_temp_directory_path(void)
{
#if (_WIN32)
char* val = (char*)malloc(sizeof(char)*(MAX_PATH + 1));
if (!val)
{
logError("Out of memory");
return NULL;
}
GetTempPath(MAX_PATH, val);

filesystem::path p((val!=0) ? val : "/tmp");
if (val) free(val);
return p;
#else
const char* val = 0;

(val = std::getenv("TMPDIR" )) ||
(val = std::getenv("TMP" )) ||
(val = std::getenv("TEMP" )) ||
(val = std::getenv("TEMPDIR"));

filesystem::path p((val!=0) ? val : "/tmp");
return p;
#endif // win32
}

filesystem::path oms_canonical(filesystem::path p)
{
return p;
}
#endif
#endif

// https://svn.boost.org/trac10/ticket/1976
Expand Down Expand Up @@ -160,12 +107,51 @@ void oms_copy_file(const filesystem::path& from, const filesystem::path& to)
#endif
}

filesystem::path oms_canonical(const filesystem::path& p)
{
#if OMC_STD_FS == 1 // C++17: it has temp_directory_path and canonical
return filesystem::canonical(p);
#elif (BOOST_VERSION >= 104600) // boost part
return filesystem::canonical(p);
#else
return p;
#endif
}

filesystem::path oms_absolute(const filesystem::path& p)
{
#if OMC_STD_FS == 1
return filesystem::absolute(p);
#else
}

filesystem::path oms_temp_directory_path(void)
{
#if OMC_STD_FS == 1 // C++17: it has temp_directory_path and canonical
return filesystem::temp_directory_path();
#elif (BOOST_VERSION >= 104600) // boost part
return filesystem::temp_directory_path();
#else // no temp_directory_path in boost < 1.46
#if (_WIN32)
char* val = (char*)malloc(sizeof(char)*(MAX_PATH + 1));
if (!val)
{
logError("Out of memory");
return NULL;
}
GetTempPath(MAX_PATH, val);

filesystem::path p((val!=0) ? val : "/tmp");
if (val) free(val);
return p;
#else // _WIN32
const char* val = 0;

(val = std::getenv("TMPDIR" )) ||
(val = std::getenv("TMP" )) ||
(val = std::getenv("TEMP" )) ||
(val = std::getenv("TEMPDIR"));

return filesystem::path((val!=0) ? val : "/tmp");
#endif // _WIN32
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions src/OMSimulatorLib/OMSFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ namespace filesystem = std::experimental::filesystem::v1;
namespace filesystem = boost::filesystem;
#endif

filesystem::path oms_temp_directory_path(void);
filesystem::path oms_canonical(filesystem::path p);
void oms_copy_file(const filesystem::path& from, const filesystem::path& to);
filesystem::path oms_unique_path(const std::string& prefix);
filesystem::path naive_uncomplete(const filesystem::path& path, const filesystem::path& base);
filesystem::path oms_unique_path(const std::string& prefix);
void oms_copy_file(const filesystem::path& from, const filesystem::path& to);
filesystem::path oms_canonical(const filesystem::path& p);
filesystem::path oms_absolute(const filesystem::path& p);
filesystem::path oms_temp_directory_path(void);

#endif