OpenTREP Logo  0.07.18
C++ Open Travel Request Parsing Library
Loading...
Searching...
No Matches
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
13namespace OPENTREP {
14
15 // //////////////////////////////////////////////////////////////////////
16 bool FileManager::checkSQLiteDirectory (const std::string& iSQLDBConnStr) {
17 bool oExistSQLDBDir = false;
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 // //////////////////////////////////////////////////////////////////////
36 checkXapianDBOnFileSystem (const TravelDBFilePath_T& iTravelDBFilePath) {
37 bool oExistXapianDBDir = false;
38
39 // Convert into Boost structure
40 boost::filesystem::path lTravelDBFilePath (iTravelDBFilePath.begin(),
41 iTravelDBFilePath.end());
42
43 // Check that the directory exists and is actually a directory
44 oExistXapianDBDir = boost::filesystem::exists (lTravelDBFilePath)
45 && boost::filesystem::is_directory (lTravelDBFilePath);
46
47 return oExistXapianDBDir;
48 }
49
50 // //////////////////////////////////////////////////////////////////////
52 recreateXapianDirectory (const std::string& iTravelDBFilePath) {
53 // Remove any existing directory for Xapian
54 boost::filesystem::path lTravelDBFilePath (iTravelDBFilePath.begin(),
55 iTravelDBFilePath.end());
56 // DEBUG
57 OPENTREP_LOG_DEBUG ("The Xapian database ('" << iTravelDBFilePath
58 << "') will be cleared");
59 boost::filesystem::remove_all (lTravelDBFilePath);
60
61 // Re-create the directory for Xapian
62 boost::filesystem::create_directories (lTravelDBFilePath);
63
64 // Check whether the just created directory exists and is a directory
65 if (!(boost::filesystem::exists (lTravelDBFilePath)
66 && boost::filesystem::is_directory (lTravelDBFilePath))) {
67 std::ostringstream oStr;
68 oStr << "The directory for the Xapian database/index ('"
69 << lTravelDBFilePath << "') cannot be created; check file-system "
70 << "permissions and whether the file-system is writable";
71 OPENTREP_LOG_ERROR (oStr.str());
72 throw FileNotFoundException (oStr.str());
73 }
74 }
75
76}
77
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition Logger.hpp:24
#define OPENTREP_LOG_DEBUG(iToBeLogged)
Definition Logger.hpp:33
static bool checkXapianDBOnFileSystem(const TravelDBFilePath_T &)
static bool checkSQLiteDirectory(const std::string &iSQLDBConnStr)
static void recreateXapianDirectory(const std::string &iTravelDBFilePath)