23
23
#include " ApplicationFeatures/LanguageFeature.h"
24
24
#include " Basics/ArangoGlobalContext.h"
25
25
26
- #include " Basics/Utf8Helper.h"
27
- #include " Basics/files.h"
28
26
#include " Basics/FileUtils.h"
27
+ #include " Basics/Utf8Helper.h"
29
28
#include " Basics/directories.h"
29
+ #include " Basics/files.h"
30
30
#include " Logger/Logger.h"
31
31
#include " ProgramOptions/ProgramOptions.h"
32
32
#include " ProgramOptions/Section.h"
@@ -37,10 +37,9 @@ using namespace arangodb::options;
37
37
38
38
LanguageFeature::LanguageFeature (
39
39
application_features::ApplicationServer* server)
40
- :
41
- ApplicationFeature(server, " Language" ),
42
- _binaryPath(server->getBinaryPath ()),
43
- _icuDataPtr(nullptr ) {
40
+ : ApplicationFeature(server, " Language" ),
41
+ _binaryPath(server->getBinaryPath ()),
42
+ _icuDataPtr(nullptr ) {
44
43
setOptional (false );
45
44
requiresElevatedPrivileges (false );
46
45
startsAfter (" Logger" );
@@ -52,57 +51,58 @@ LanguageFeature::~LanguageFeature() {
52
51
}
53
52
}
54
53
55
-
56
54
void LanguageFeature::collectOptions (
57
55
std::shared_ptr<options::ProgramOptions> options) {
58
56
options->addHiddenOption (" --default-language" , " ISO-639 language code" ,
59
57
new StringParameter (&_language));
60
58
}
61
59
62
- void * LanguageFeature::prepareIcu (std::string const & binaryPath, std::string const & binaryExecutionPath, std::string& path, std::string const & binaryName) {
60
+ void * LanguageFeature::prepareIcu (std::string const & binaryPath,
61
+ std::string const & binaryExecutionPath,
62
+ std::string& path,
63
+ std::string const & binaryName) {
63
64
char const * icuDataEnv = getenv (" ICU_DATA" );
64
-
65
65
std::string fn (" icudtl.dat" );
66
+
66
67
if (icuDataEnv != nullptr ) {
67
- path = icuDataEnv + fn ;
68
+ path = FileUtils::buildFilename ( icuDataEnv, fn) ;
68
69
}
69
70
70
71
if (path.empty () || !TRI_IsRegularFile (path.c_str ())) {
71
72
if (!path.empty ()) {
72
73
LOG_TOPIC (WARN, arangodb::Logger::FIXME)
73
- << " failed to locate '" << fn
74
- << " ' at '" << path << " '" ;
74
+ << " failed to locate '" << fn << " ' at '" << path << " '" ;
75
75
}
76
- std::string bpfn = binaryExecutionPath + TRI_DIR_SEPARATOR_STR + fn;
77
-
76
+
77
+ std::string bpfn = FileUtils::buildFilename (binaryExecutionPath, fn);
78
+
78
79
if (TRI_IsRegularFile (fn.c_str ())) {
79
80
path = fn;
80
- }
81
- else if (TRI_IsRegularFile (bpfn.c_str ())) {
81
+ } else if (TRI_IsRegularFile (bpfn.c_str ())) {
82
82
path = bpfn;
83
- }
84
- else {
85
- std::string argv_0 = binaryExecutionPath + TRI_DIR_SEPARATOR_STR + binaryName;
83
+ } else {
84
+ std::string argv_0 = FileUtils::buildFilename (binaryExecutionPath, binaryName);
86
85
path = TRI_LocateInstallDirectory (argv_0.c_str (), binaryPath.c_str ());
87
- path += ICU_DESTINATION_DIRECTORY TRI_DIR_SEPARATOR_STR + fn;
86
+ path = FileUtils::buildFilename (path, ICU_DESTINATION_DIRECTORY, fn);
87
+
88
88
if (!TRI_IsRegularFile (path.c_str ())) {
89
- // Try whether we have an absolute install prefix:
90
- path = ICU_DESTINATION_DIRECTORY TRI_DIR_SEPARATOR_STR + fn ;
89
+ // Try whether we have an absolute install prefix:
90
+ path = FileUtils::buildFilename ( ICU_DESTINATION_DIRECTORY, fn) ;
91
91
}
92
92
}
93
+
93
94
if (!TRI_IsRegularFile (path.c_str ())) {
94
- std::string msg =
95
- std::string ( " cannot locate ' " ) + path + " '; please make sure it is available; "
96
- " the variable ICU_DATA='" ;
95
+ std::string msg = std::string ( " cannot locate ' " ) + path +
96
+ " '; please make sure it is available; "
97
+ " the variable ICU_DATA='" ;
97
98
if (getenv (" ICU_DATA" ) != nullptr ) {
98
99
msg += getenv (" ICU_DATA" );
99
100
}
100
101
msg += " ' should point to the directory containing '" + fn + " '" ;
101
102
102
103
LOG_TOPIC (FATAL, arangodb::Logger::FIXME) << msg;
103
104
FATAL_ERROR_EXIT ();
104
- }
105
- else {
105
+ } else {
106
106
std::string icu_path = path.substr (0 , path.length () - fn.length ());
107
107
FileUtils::makePathAbsolute (icu_path);
108
108
FileUtils::normalizePath (icu_path);
@@ -117,7 +117,9 @@ void* LanguageFeature::prepareIcu(std::string const& binaryPath, std::string con
117
117
void * icuDataPtr = TRI_SlurpFile (TRI_UNKNOWN_MEM_ZONE, path.c_str (), nullptr );
118
118
119
119
if (icuDataPtr == nullptr ) {
120
- LOG_TOPIC (FATAL, arangodb::Logger::FIXME) << " failed to load '" << fn << " ' at '" << path << " ' - " << TRI_last_error ();
120
+ LOG_TOPIC (FATAL, arangodb::Logger::FIXME)
121
+ << " failed to load '" << fn << " ' at '" << path << " ' - "
122
+ << TRI_last_error ();
121
123
FATAL_ERROR_EXIT ();
122
124
}
123
125
return icuDataPtr;
@@ -128,11 +130,14 @@ void LanguageFeature::prepare() {
128
130
auto context = ArangoGlobalContext::CONTEXT;
129
131
std::string binaryExecutionPath = context->getBinaryPath ();
130
132
std::string binaryName = context->binaryName ();
131
- _icuDataPtr = LanguageFeature::prepareIcu (_binaryPath, binaryExecutionPath, p, binaryName);
133
+ _icuDataPtr = LanguageFeature::prepareIcu (_binaryPath, binaryExecutionPath, p,
134
+ binaryName);
132
135
133
- if (!Utf8Helper::DefaultUtf8Helper.setCollatorLanguage (_language, _icuDataPtr)) {
134
- LOG_TOPIC (FATAL, arangodb::Logger::FIXME) << " error initializing ICU with the contents of '" << p << " '" ;
135
- FATAL_ERROR_EXIT ();
136
+ if (!Utf8Helper::DefaultUtf8Helper.setCollatorLanguage (_language,
137
+ _icuDataPtr)) {
138
+ LOG_TOPIC (FATAL, arangodb::Logger::FIXME)
139
+ << " error initializing ICU with the contents of '" << p << " '" ;
140
+ FATAL_ERROR_EXIT ();
136
141
}
137
142
}
138
143
@@ -147,5 +152,6 @@ void LanguageFeature::start() {
147
152
languageName = Utf8Helper::DefaultUtf8Helper.getCollatorLanguage ();
148
153
}
149
154
150
- LOG_TOPIC (DEBUG, arangodb::Logger::FIXME) << " using default language '" << languageName << " '" ;
155
+ LOG_TOPIC (DEBUG, arangodb::Logger::FIXME)
156
+ << " using default language '" << languageName << " '" ;
151
157
}
0 commit comments