OpenTREP Logo  0.07.1
C++ Open Travel Request Parsing Library
FileManager.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // Boost
8 #include <boost/filesystem.hpp>
9 // OpenTrep
12 
13 namespace OPENTREP {
14 
15  // //////////////////////////////////////////////////////////////////////
16  bool FileManager::checkSQLiteDirectory (const std::string& iSQLDBConnStr) {
17  bool oExistSQLDBDir = true;
18 
19  // Retrieve the full file-path of the SQLite3 directory
20  boost::filesystem::path lSQLiteDBFullPath (iSQLDBConnStr.begin(),
21  iSQLDBConnStr.end());
22 
23  // Retrieve the directory hosting the SQLite3 database
24  boost::filesystem::path lSQLiteDBParentPath =
25  lSQLiteDBFullPath.parent_path();
26 
27  // Check that the directory exists and is actually a directory
28  oExistSQLDBDir = boost::filesystem::exists (lSQLiteDBParentPath)
29  && boost::filesystem::is_directory (lSQLiteDBParentPath);
30 
31  return oExistSQLDBDir;
32  }
33 
34  // //////////////////////////////////////////////////////////////////////
35  void FileManager::
36  recreateXapianDirectory (const std::string& iTravelDBFilePath) {
37  // Remove any existing directory for Xapian
38  boost::filesystem::path lTravelDBFilePath (iTravelDBFilePath.begin(),
39  iTravelDBFilePath.end());
40  // DEBUG
41  OPENTREP_LOG_DEBUG ("The Xapian database ('" << iTravelDBFilePath
42  << "') will be cleared");
43  boost::filesystem::remove_all (lTravelDBFilePath);
44 
45  // Re-create the directory for Xapian
46  boost::filesystem::create_directories (lTravelDBFilePath);
47 
48  // Check whether the just created directory exists and is a directory
49  if (!(boost::filesystem::exists (lTravelDBFilePath)
50  && boost::filesystem::is_directory (lTravelDBFilePath))) {
51  std::ostringstream oStr;
52  oStr << "The file-path to the Xapian database/index ('"
53  << lTravelDBFilePath << "') does not exist or is not a directory.";
54  OPENTREP_LOG_ERROR (oStr.str());
55  throw FileNotFoundException (oStr.str());
56  }
57  }
58 
59 }
60 
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition: Logger.hpp:24
#define OPENTREP_LOG_DEBUG(iToBeLogged)
Definition: Logger.hpp:33
static bool checkSQLiteDirectory(const std::string &iSQLDBConnStr)
Definition: FileManager.cpp:16
static void recreateXapianDirectory(const std::string &iTravelDBFilePath)
Definition: FileManager.cpp:36