diff --git a/modules/fs/include/fs/Files.h b/modules/fs/include/fs/Files.h index bcf6b8554673b40ea832eb0818af06a92c674d0b..567181fe840f96c3f54a3ca334c4eec8b92761d8 100644 --- a/modules/fs/include/fs/Files.h +++ b/modules/fs/include/fs/Files.h @@ -38,10 +38,9 @@ namespace FS static bool getFilenameExtension(const char* path, char* fileNameExtension); static bool getFilenameExtension(const char* path, char* fileNameExtension, size_t size); -#if BOOST_VERSION / 100 % 1000 != 54 static bool copyFile(const char* sSourceFile, const char* sDestination); static bool copyDirectory(const char* sourceDir, const char* targetDir); -#endif + static bool remove(const char* path); static bool removeAll(const char* path); private: diff --git a/modules/fs/src/Files.cpp b/modules/fs/src/Files.cpp index 354cbae7a17c640442e7907c126b89b4c9571ed1..b93d3813ba7e0738bf541817d03ceeaf2df76c3e 100644 --- a/modules/fs/src/Files.cpp +++ b/modules/fs/src/Files.cpp @@ -5,6 +5,7 @@ #include <unistd.h> //For access(). #include <sys/stat.h> #include <sys/types.h> // For stat(). + #include <cstdlib> #elif defined TARGET_OS_Windows #include "m_ConverterUtf8.h" #include <Windows.h> @@ -26,7 +27,7 @@ using namespace std; // a 'boolean' type. Thus the following define to // force the use of FS::boolean ! -#if BOOST_VERSION / 100 % 1000 != 54 +#if defined TARGET_HAS_Boost && BOOST_VERSION / 100 % 1000 >= 55 /** * \brief Makes a recursive copy of source folder to target folder. * Operation can fail in several cases: @@ -431,7 +432,41 @@ bool Files::getFilenameExtension(const char* path, char* fileNameExtension, size return true; } -#if BOOST_VERSION / 100 % 1000 != 54 +bool Files::remove(const char* path) +{ + if (FS::Files::fileExists(path) || FS::Files::directoryExists(path)) + { +#if defined TARGET_OS_Windows + std::wstring pathUTF16 = Common::Converter::utf8_to_utf16(path); + return boost::filesystem::remove(boost::filesystem::wpath(pathUTF16.c_str())); +#else + return boost::filesystem::remove(boost::filesystem::path(path)); +#endif + } + return true; +} + +bool Files::removeAll(const char* path) +{ + if (FS::Files::fileExists(path) || FS::Files::directoryExists(path)) + { +#if defined TARGET_OS_Windows + std::wstring pathUTF16 = Common::Converter::utf8_to_utf16(path); + return (boost::filesystem::remove_all(boost::filesystem::wpath(pathUTF16.c_str())) != 0); +#else + return (boost::filesystem::remove_all(boost::filesystem::path(path)) != 0); +#endif + } + return true; +} + + + +// old boost compliance +// manage cases here + +#if defined TARGET_HAS_Boost && BOOST_VERSION / 100 % 1000 >= 55 + bool Files::copyFile(const char* sSourceFile, const char* sDestinationPath) { if(!sSourceFile || !sDestinationPath) @@ -450,6 +485,10 @@ bool Files::copyFile(const char* sSourceFile, const char* sDestinationPath) bool Files::copyDirectory(const char* sourceDir, const char* targetDir) { + if(!sourceDir || !targetDir) + { + return false; + } #if defined TARGET_OS_Windows wstring pathSourceUTF16 = Common::Converter::utf8_to_utf16(sourceDir); wstring pathTargetUTF16 = Common::Converter::utf8_to_utf16(targetDir); @@ -462,35 +501,44 @@ bool Files::copyDirectory(const char* sourceDir, const char* targetDir) return recursiveCopy(source, target); } -#endif +#elif defined TARGET_OS_Windows +#error OpenViBE requires at least boost 1.55 to compile on Windows -bool Files::remove(const char* path) +#else +// ugly hack for old boost on linux ... +bool Files::copyFile(const char* sSourceFile, const char* sDestinationPath) { - if (FS::Files::fileExists(path) || FS::Files::directoryExists(path)) + if(!sSourceFile || !sDestinationPath) { -#if defined TARGET_OS_Windows - std::wstring pathUTF16 = Common::Converter::utf8_to_utf16(path); - return boost::filesystem::remove(boost::filesystem::wpath(pathUTF16.c_str())); -#else - return boost::filesystem::remove(boost::filesystem::path(path)); -#endif + return false; } - return true; + + if (FS::Files::fileExists(sDestinationPath)) + { + return false; + } + + std::string command = std::string("cp '") + sSourceFile + "' '" + sDestinationPath+"'"; + + return (std::system(command.c_str()) != -1); } -bool Files::removeAll(const char* path) +bool Files::copyDirectory(const char* sourceDir, const char* targetDir) { - if (FS::Files::fileExists(path) || FS::Files::directoryExists(path)) + + if(!sourceDir || !sourceDir) { -#if defined TARGET_OS_Windows - std::wstring pathUTF16 = Common::Converter::utf8_to_utf16(path); - return (boost::filesystem::remove_all(boost::filesystem::wpath(pathUTF16.c_str())) != 0); -#else - return (boost::filesystem::remove_all(boost::filesystem::path(path)) != 0); -#endif + return false; } - return true; + + if (FS::Files::directoryExists(targetDir)) + { + return false; + } + + std::string command = std::string("cp -r '") + sourceDir + "' '" + targetDir+"'"; + return (std::system(command.c_str()) != -1); } - +#endif diff --git a/unit-test/openvibe-module-fs/uoFilesTestUTF.cpp b/unit-test/openvibe-module-fs/uoFilesTestUTF.cpp index 9250dd370a530622974e6cd3c4a2323223f318ee..c90a960af9517c5021a328128dfb80565c151992 100644 --- a/unit-test/openvibe-module-fs/uoFilesTestUTF.cpp +++ b/unit-test/openvibe-module-fs/uoFilesTestUTF.cpp @@ -83,7 +83,7 @@ TEST(FS_Files_Test_Directories_UTF, validateCreateParentPath) ASSERT_TRUE(FS::Files::directoryExists(TEMP_OUTPUT_DIR)); } -#if BOOST_VERSION / 100 % 1000 != 54 +#if BOOST_VERSION / 100 % 1000 >= 55 TEST(FS_Files_Test_Directories_UTF, validateCopyFile) { FS::Files::removeAll(TEMP_OUTPUT_ASCII_FILE_PATH);