From 836954b8e3a442c522bcc0fddb51e4a8177d8734 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 30 Nov 2018 17:25:50 +0100 Subject: [PATCH] allow using UTF8 filenames for UUID directory (#7569) --- arangod/Cluster/ServerState.cpp | 26 +++++++++++++------------- lib/V8/v8-utils.cpp | 24 +++++++++++++++--------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/arangod/Cluster/ServerState.cpp b/arangod/Cluster/ServerState.cpp index 3ff4825895..4c88aba417 100644 --- a/arangod/Cluster/ServerState.cpp +++ b/arangod/Cluster/ServerState.cpp @@ -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(); } } diff --git a/lib/V8/v8-utils.cpp b/lib/V8/v8-utils.cpp index 9cdd97eaf5..af95a51a55 100644 --- a/lib/V8/v8-utils.cpp +++ b/lib/V8/v8-utils.cpp @@ -2648,10 +2648,20 @@ static void JS_Append(v8::FunctionCallbackInfo const& args) { TRI_V8_THROW_EXCEPTION_USAGE("append(, )"); } - TRI_Utf8ValueNFC name(args[0]); +#if _WIN32 // the wintendo needs utf16 filenames + v8::String::Value str(args[0]); + std::wstring name { + reinterpret_cast(*str), + static_cast(str.length())}; +#else + TRI_Utf8ValueNFC str(args[0]); + std::string name(*str, str.length()); +#endif + + std::ofstream file; - if (*name == nullptr) { - TRI_V8_THROW_TYPE_ERROR(" must be a string"); + if (name.empty()) { + TRI_V8_THROW_TYPE_ERROR(" 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 const& args) { "invalid 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 const& args) { TRI_V8_THROW_TYPE_ERROR(" 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());