mirror of https://gitee.com/bigwinds/arangodb
allow using UTF8 filenames for UUID directory (#7569)
This commit is contained in:
parent
3c3fa4606d
commit
836954b8e3
|
@ -436,16 +436,18 @@ bool ServerState::hasPersistedId() {
|
||||||
|
|
||||||
bool ServerState::writePersistedId(std::string const& id) {
|
bool ServerState::writePersistedId(std::string const& id) {
|
||||||
std::string uuidFilename = getUuidFilename();
|
std::string uuidFilename = getUuidFilename();
|
||||||
mkdir(FileUtils::dirname(uuidFilename));
|
// try to create underlying directory
|
||||||
std::ofstream ofs(uuidFilename);
|
int error;
|
||||||
if (!ofs.is_open()) {
|
FileUtils::createDirectory(FileUtils::dirname(uuidFilename), &error);
|
||||||
LOG_TOPIC(FATAL, Logger::CLUSTER)
|
|
||||||
<< "Couldn't write id file " << getUuidFilename();
|
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();
|
FATAL_ERROR_EXIT();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
ofs << id << std::endl;
|
|
||||||
ofs.close();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -466,11 +468,9 @@ std::string ServerState::getPersistedId() {
|
||||||
if (!uuidBuf.empty()) {
|
if (!uuidBuf.empty()) {
|
||||||
return uuidBuf;
|
return uuidBuf;
|
||||||
}
|
}
|
||||||
}
|
} catch (arangodb::basics::Exception const& ex) {
|
||||||
catch (arangodb::basics::Exception const& ex) {
|
LOG_TOPIC(FATAL, arangodb::Logger::CLUSTER)
|
||||||
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "Couldn't read UUID file '"
|
<< "Couldn't read UUID file '" << uuidFilename << "' - " << ex.what();
|
||||||
<< uuidFilename << "' - "
|
|
||||||
<< ex.what();
|
|
||||||
FATAL_ERROR_EXIT();
|
FATAL_ERROR_EXIT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2648,10 +2648,20 @@ static void JS_Append(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
||||||
TRI_V8_THROW_EXCEPTION_USAGE("append(<filename>, <content>)");
|
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) {
|
std::ofstream file;
|
||||||
TRI_V8_THROW_TYPE_ERROR("<filename> must be a string");
|
|
||||||
|
if (name.empty()) {
|
||||||
|
TRI_V8_THROW_TYPE_ERROR("<filename> must be a non-empty string");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[1]->IsObject() && V8Buffer::hasInstance(isolate, args[1])) {
|
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");
|
"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()) {
|
if (file.is_open()) {
|
||||||
file.write(data, size);
|
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");
|
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()) {
|
if (file.is_open()) {
|
||||||
file.write(*content, content.length());
|
file.write(*content, content.length());
|
||||||
|
|
Loading…
Reference in New Issue