Skip to content

Commit

Permalink
switch to boost filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
xchrdw committed Mar 31, 2014
1 parent 7d98bb5 commit eef4391
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 34 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ find_package(LibOVR REQUIRED)
find_package(OpenMP REQUIRED)
find_package(Lua52 REQUIRED)


if(REGEX_USE_BOOST)
find_package(Boost REQUIRED regex)
if(USE_BOOST)
message("find ${USE_BOOST}")
find_package(Boost REQUIRED ${USE_BOOST})
endif()

if(OPENMP_FOUND)
Expand Down
6 changes: 5 additions & 1 deletion cmake/PlatformLinuxGCC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ else()
endif()

if(GCC_VERSION VERSION_LESS 4.9)
set(REGEX_USE_BOOST TRUE)
set(USE_BOOST ${USE_BOOST} regex)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DREGEX_USE_BOOST")
endif()

set(USE_BOOST ${USE_BOOST} system filesystem) # until gcc implements <filesystem>
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFILESYSTEM_USE_BOOST")


set(LINUX_COMPILE_DEFS
LINUX # Linux system
PIC # Position-independent code
Expand Down
3 changes: 2 additions & 1 deletion lib/setup_libs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

sudo apt-get install -y build-essential xorg-dev libglu1-mesa-dev cmake \
libboost-regex1.54-dev libudev-dev libopenal-dev libsndfile1-dev libjpeg-dev liblua5.2-dev
libboost-regex1.54-dev libboost-filesystem1.54-dev libudev-dev \
libopenal-dev libsndfile1-dev libjpeg-dev liblua5.2-dev

pushd `dirname $0`

Expand Down
8 changes: 8 additions & 0 deletions src/utils/def_filesystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#ifdef FILESYSTEM_USE_BOOST
#include <boost/filesystem.hpp>
namespace filesystem = boost::filesystem;
#else
#include <filesystem>
namespace filesystem = std::tr2::sys;
#endif
36 changes: 7 additions & 29 deletions src/utils/filesystem.cpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,27 @@
#include "filesystem.h"

#ifdef WIN32
#include <filesystem>
namespace std {
namespace sys = tr2::sys;
}
#else
#include <dirent.h>
#include <unistd.h>
#endif

#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>

#include "def_filesystem.h"

bool FileSystem::exists(const std::string& path) {
struct stat info;
if (stat(path.c_str(), &info) != 0) {
return false;
} else {
int exists = info.st_mode & (S_IFREG | S_IFDIR); // is file or directory
return exists != 0;
}
return filesystem::exists(filesystem::path(path));
}

bool FileSystem::removeFile(const std::string& path) {
return ::remove(path.c_str()) == 0;
return filesystem::remove(filesystem::path(path));
}

bool FileSystem::createDirectory(const std::string& path) {
#ifdef WIN32
return std::sys::create_directory(std::sys::path(path));
#else
return mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0;
#endif
return filesystem::create_directory(filesystem::path(path));
}

bool FileSystem::removeDirectory(const std::string& path) {
#ifdef WIN32
return std::sys::remove_directory(std::sys::path(path));
#ifdef WIN32
return filesystem::remove_directory(filesystem::path(path));
#else
return rmdir(path.c_str()) == 0;
return filesystem::remove(filesystem::path(path));
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions test/property/testproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ go_bandit([](){

it("can iterate directories", [&]() {
std::string dir = FileSystem::userConfigDir() + "/test";
AssertThat(FileSystem::exists(dir), Equals(false));
FileSystem::createDirectory(dir);

std::ofstream(dir + "/test1.txt").close();
Expand All @@ -182,6 +183,7 @@ go_bandit([](){
FileSystem::removeFile(dir + "/test2.txt");
FileSystem::removeDirectory(dir + "/test3");
FileSystem::removeDirectory(dir);

});
});
});
Expand Down

0 comments on commit eef4391

Please sign in to comment.