26 #include <boost/filesystem/operations.hpp>
27 #include <boost/filesystem/path.hpp>
28 #include <boost/version.hpp>
34 #include "vfs/raw/rawdata.h"
35 #include "vfs/raw/rawdatafile.h"
36 #include "util/log/logger.h"
37 #include "util/base/exception.h"
38 #include "vfsdirectory.h"
40 namespace bfs = boost::filesystem;
46 #define BOOST_MAJOR_VERSION BOOST_VERSION / 100000
47 #define BOOST_MINOR_VERSION BOOST_VERSION / 100 % 1000
49 #if (BOOST_MAJOR_VERSION >= 1 && BOOST_MINOR_VERSION >= 46)
53 #define USE_BOOST_FILESYSTEM_V3
54 #elif (BOOST_MAJOR_VERSION >= 1 && BOOST_MINOR_VERSION >= 36)
58 #define USE_NON_DEPRECATED_BOOST_FILESYSTEM_V2
63 static Logger _log(LM_VFS);
66 FL_DBG(_log,
LMsg(
"VFSDirectory created with root path ") << m_root);
67 if(!m_root.empty() && *(m_root.end() - 1) !=
'/')
77 std::string fullpath = m_root + name;
78 std::ifstream file(fullpath.c_str());
90 return list(path,
false);
94 return list(path,
true);
97 std::set<std::string> VFSDirectory::list(
const std::string& path,
bool directorys)
const {
98 std::set<std::string> list;
99 std::string dir = m_root;
102 if(path[0] ==
'/' && m_root[m_root.size()-1] ==
'/') {
103 dir.append(path.substr(1));
110 bfs::path boost_path(dir);
111 if (!bfs::exists(boost_path) || !bfs::is_directory(boost_path))
114 bfs::directory_iterator end;
115 for (bfs::directory_iterator i(boost_path); i != end; ++i) {
116 if (bfs::is_directory(*i) != directorys)
119 #if defined(USE_BOOST_FILESYSTEM_V3)
124 bfs::path filenamePath = i->path().filename();
125 list.insert(filenamePath.string());
126 #elif defined(USE_NON_DEPRECATED_BOOST_FILESYSTEM_V2)
130 list.insert(i->path().filename());
135 list.insert(i->leaf());
139 catch (
const bfs::filesystem_error& ex) {
140 throw Exception(ex.what());