1
0
Fork 0

allow using UTF8 filenames for UUID directory (#7569)

This commit is contained in:
Jan 2018-11-30 17:25:50 +01:00 committed by GitHub
parent 3c3fa4606d
commit 836954b8e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 22 deletions

View File

@ -436,16 +436,18 @@ bool ServerState::hasPersistedId() {
bool ServerState::writePersistedId(std::string const& id) {
std::string uuidFilename = getUuidFilename();
mkdir(FileUtils::dirname(uuidFilename));
std::ofstream ofs(uuidFilename);
if (!ofs.is_open()) {
LOG_TOPIC(FATAL, Logger::CLUSTER)
<< "Couldn't write id file " << getUuidFilename();
// try to create underlying directory
int error;
FileUtils::createDirectory(FileUtils::dirname(uuidFilename), &error);
try {
arangodb::basics::FileUtils::spit(uuidFilename, id, true);
} catch (arangodb::basics::Exception const& ex) {
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "Cannot write UUID file '"
<< uuidFilename << "': "
<< ex.what();
FATAL_ERROR_EXIT();
return false;
}
ofs << id << std::endl;
ofs.close();
return true;
}
@ -466,11 +468,9 @@ std::string ServerState::getPersistedId() {
if (!uuidBuf.empty()) {
return uuidBuf;
}
}
catch (arangodb::basics::Exception const& ex) {
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "Couldn't read UUID file '"
<< uuidFilename << "' - "
<< ex.what();
} catch (arangodb::basics::Exception const& ex) {
LOG_TOPIC(FATAL, arangodb::Logger::CLUSTER)
<< "Couldn't read UUID file '" << uuidFilename << "' - " << ex.what();
FATAL_ERROR_EXIT();
}
}

View File

@ -2648,10 +2648,20 @@ static void JS_Append(v8::FunctionCallbackInfo<v8::Value> const& args) {
TRI_V8_THROW_EXCEPTION_USAGE("append(<filename>, <content>)");
}
TRI_Utf8ValueNFC name(args[0]);
#if _WIN32 // the wintendo needs utf16 filenames
v8::String::Value str(args[0]);
std::wstring name {
reinterpret_cast<wchar_t *>(*str),
static_cast<size_t>(str.length())};
#else
TRI_Utf8ValueNFC str(args[0]);
std::string name(*str, str.length());
#endif
if (*name == nullptr) {
TRI_V8_THROW_TYPE_ERROR("<filename> must be a string");
std::ofstream file;
if (name.empty()) {
TRI_V8_THROW_TYPE_ERROR("<filename> must be a non-empty string");
}
if (args[1]->IsObject() && V8Buffer::hasInstance(isolate, args[1])) {
@ -2664,9 +2674,7 @@ static void JS_Append(v8::FunctionCallbackInfo<v8::Value> const& args) {
"invalid <content> buffer value");
}
std::ofstream file;
file.open(*name, std::ios::out | std::ios::binary | std::ios::app);
file.open(name, std::ios::out | std::ios::binary | std::ios::app);
if (file.is_open()) {
file.write(data, size);
@ -2680,9 +2688,7 @@ static void JS_Append(v8::FunctionCallbackInfo<v8::Value> const& args) {
TRI_V8_THROW_TYPE_ERROR("<content> must be a string");
}
std::ofstream file;
file.open(*name, std::ios::out | std::ios::binary | std::ios::app);
file.open(name, std::ios::out | std::ios::binary | std::ios::app);
if (file.is_open()) {
file.write(*content, content.length());