0.08.01
C++ Open Travel Request Parsing Library
Toggle main menu visibility
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
10
#include <
opentrep/command/FileManager.hpp
>
11
#include <
opentrep/service/Logger.hpp
>
12
13
namespace
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
// //////////////////////////////////////////////////////////////////////
35
bool
FileManager::
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
// //////////////////////////////////////////////////////////////////////
51
void
FileManager::
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
FileManager.hpp
Logger.hpp
OPENTREP_LOG_ERROR
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition
Logger.hpp:24
OPENTREP_LOG_DEBUG
#define OPENTREP_LOG_DEBUG(iToBeLogged)
Definition
Logger.hpp:33
OPENTREP::FileManager::checkXapianDBOnFileSystem
static bool checkXapianDBOnFileSystem(const TravelDBFilePath_T &)
Definition
FileManager.cpp:36
OPENTREP::FileManager::checkSQLiteDirectory
static bool checkSQLiteDirectory(const std::string &iSQLDBConnStr)
Definition
FileManager.cpp:16
OPENTREP::FileManager::recreateXapianDirectory
static void recreateXapianDirectory(const std::string &iTravelDBFilePath)
Definition
FileManager.cpp:52
OPENTREP::FileNotFoundException
Definition
OPENTREP_exceptions.hpp:145
OPENTREP
Definition
BasChronometer.cpp:10
OPENTREP::TravelDBFilePath_T
Definition
OPENTREP_Types.hpp:46
Generated on
for OpenTREP by
1.17.0