diff --git a/arangod/VocBase/vocbase.cpp b/arangod/VocBase/vocbase.cpp index 5bfa2c29bc..6d696c11a6 100644 --- a/arangod/VocBase/vocbase.cpp +++ b/arangod/VocBase/vocbase.cpp @@ -1368,17 +1368,6 @@ static bool FilenameStringComparator (std::string const& lhs, std::string const& return numLeft < numRight; } -//////////////////////////////////////////////////////////////////////////////// -///// @brief parses a json file to VelocyPack -////////////////////////////////////////////////////////////////////////////////// - -static std::shared_ptr TRI_VelocyPackFile (char const* path) { - size_t length; - char* content = TRI_SlurpFile(TRI_UNKNOWN_MEM_ZONE, path, &length); - // The Parser might THROW - return VPackParser::fromJson(reinterpret_cast(content), length); -} - // ----------------------------------------------------------------------------- // --SECTION-- class TRI_vocbase_col_t // ----------------------------------------------------------------------------- @@ -1388,8 +1377,9 @@ void TRI_vocbase_col_t::toVelocyPack (VPackBuilder& builder, TRI_voc_tick_t maxTick) { TRI_ASSERT(! builder.isClosed()); char* filename = TRI_Concatenate2File(_path, TRI_VOC_PARAMETER_FILE); + std::string path = std::string(filename, strlen(filename)); - std::shared_ptr fileInfoBuilder = TRI_VelocyPackFile(filename); + std::shared_ptr fileInfoBuilder = triagens::basics::VelocyPackHelper::velocyPackFromFile(path); builder.add("parameters", fileInfoBuilder->slice()); TRI_FreeString(TRI_CORE_MEM_ZONE, filename); @@ -1430,7 +1420,8 @@ void TRI_vocbase_col_t::toVelocyPackIndexes (VPackBuilder& builder, for (auto const& file : files) { if (regexec(&re, file.c_str(), (size_t) 0, nullptr, 0) == 0) { char* fqn = TRI_Concatenate2File(_path, file.c_str()); - std::shared_ptr indexVPack = TRI_VelocyPackFile(fqn); + std::string path = std::string(fqn, strlen(fqn)); + std::shared_ptr indexVPack = triagens::basics::VelocyPackHelper::velocyPackFromFile(path); TRI_FreeString(TRI_CORE_MEM_ZONE, fqn); VPackSlice const indexSlice = indexVPack->slice(); diff --git a/arangosh/V8Client/arangorestore.cpp b/arangosh/V8Client/arangorestore.cpp index fcc3fcf889..efd014a82f 100644 --- a/arangosh/V8Client/arangorestore.cpp +++ b/arangosh/V8Client/arangorestore.cpp @@ -567,17 +567,6 @@ static bool SortCollections (VPackSlice const& l, return strcasecmp(leftName.c_str(), rightName.c_str()) < 0; } -//////////////////////////////////////////////////////////////////////////////// -///// @brief parses a json file to VelocyPack -////////////////////////////////////////////////////////////////////////////////// - -static std::shared_ptr readVelocyPackFile (std::string path) { - size_t length; - char* content = TRI_SlurpFile(TRI_UNKNOWN_MEM_ZONE, path.c_str(), &length); - // The Parser might THROW - return VPackParser::fromJson(reinterpret_cast(content), length); -} - //////////////////////////////////////////////////////////////////////////////// /// @brief process all files from the input directory //////////////////////////////////////////////////////////////////////////////// @@ -615,7 +604,7 @@ static int ProcessInputDirectory (std::string& errorMsg) { } const string fqn = InputDirectory + TRI_DIR_SEPARATOR_STR + file; - std::shared_ptr fileContentBuilder = readVelocyPackFile(fqn); + std::shared_ptr fileContentBuilder = triagens::basics::VelocyPackHelper::velocyPackFromFile(fqn); VPackSlice const fileContent = fileContentBuilder->slice(); if (! fileContent.isObject()) { diff --git a/lib/Basics/VelocyPackHelper.cpp b/lib/Basics/VelocyPackHelper.cpp index e54885d115..0f1d043c86 100644 --- a/lib/Basics/VelocyPackHelper.cpp +++ b/lib/Basics/VelocyPackHelper.cpp @@ -27,6 +27,7 @@ #include "Basics/VelocyPackHelper.h" #include "Basics/Exceptions.h" +#include "Basics/files.h" using VelocyPackHelper = triagens::basics::VelocyPackHelper; @@ -91,6 +92,17 @@ TRI_json_t* VelocyPackHelper::velocyPackToJson (VPackSlice const& slice) { return JsonHelper::fromString(slice.toJson()); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief parses a json file to VelocyPack +////////////////////////////////////////////////////////////////////////////////// + +std::shared_ptr VelocyPackHelper::velocyPackFromFile (std::string const& path) { + size_t length; + char* content = TRI_SlurpFile(TRI_UNKNOWN_MEM_ZONE, path.c_str(), &length); + // The Parser might THROW + return VPackParser::fromJson(reinterpret_cast(content), length); +} + // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE // ----------------------------------------------------------------------------- diff --git a/lib/Basics/VelocyPackHelper.h b/lib/Basics/VelocyPackHelper.h index 59305175b4..0ce34182e7 100644 --- a/lib/Basics/VelocyPackHelper.h +++ b/lib/Basics/VelocyPackHelper.h @@ -113,6 +113,12 @@ namespace triagens { //////////////////////////////////////////////////////////////////////////////// static TRI_json_t* velocyPackToJson (VPackSlice const&); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief parses a json file to VelocyPack +////////////////////////////////////////////////////////////////////////////////// + + static std::shared_ptr velocyPackFromFile (std::string const& path); }; } }