Skip to content

Commit

Permalink
Cleanup the filesystem package (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Jul 7, 2021
1 parent a6d1c8a commit dac1571
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 60 deletions.
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

0 comments on commit dac1571

Please sign in to comment.