mirror of https://gitee.com/bigwinds/arangodb
- Replace the javascript implementation of makeDirectoryRecursive by our native implementation
- fix the native implementation so it doesn't try to create driveletters as directories.
This commit is contained in:
parent
2b04526729
commit
0690b4943f
|
@ -1,5 +1,6 @@
|
|||
/*jshint -W051: true */
|
||||
/*global require, FS_MAKE_DIRECTORY, FS_MOVE, FS_REMOVE, FS_REMOVE_DIRECTORY, FS_LIST,
|
||||
/*global require, FS_MAKE_DIRECTORY, FS_MAKE_DIRECTORY_RECURSIVE,
|
||||
FS_MOVE, FS_REMOVE, FS_REMOVE_DIRECTORY, FS_LIST,
|
||||
FS_REMOVE_RECURSIVE_DIRECTORY, FS_EXISTS, FS_CHMOD, FS_IS_DIRECTORY, FS_IS_FILE,
|
||||
FS_MAKE_ABSOLUTE, FS_FILESIZE, FS_GET_TEMP_FILE, FS_GET_TEMP_PATH, FS_LIST_TREE,
|
||||
FS_UNZIP_FILE, FS_ZIP_FILE, FS_MTIME, SYS_READ, SYS_READ_BUFFER, SYS_READ64, SYS_SAVE,
|
||||
|
@ -404,33 +405,10 @@
|
|||
/// @brief makeDirectoryRecursive
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.makeDirectoryRecursive = function (path) {
|
||||
'use strict';
|
||||
|
||||
var parts, subPart;
|
||||
|
||||
parts = path.split(exports.pathSeparator);
|
||||
subPart = '';
|
||||
|
||||
parts.forEach(function (s, i) {
|
||||
if (i > 0) {
|
||||
subPart += exports.pathSeparator;
|
||||
}
|
||||
subPart += s;
|
||||
if (subPart.length > 0) {
|
||||
try {
|
||||
// directory may already exist
|
||||
exports.makeDirectory(subPart);
|
||||
}
|
||||
catch (err) {
|
||||
if (err.errorNum !==
|
||||
require("internal").errors.ERROR_FILE_EXISTS.code) {
|
||||
throw(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
if (typeof FS_MAKE_DIRECTORY_RECURSIVE !== "undefined") {
|
||||
exports.makeDirectoryRecursive = FS_MAKE_DIRECTORY_RECURSIVE;
|
||||
delete FS_MAKE_DIRECTORY_RECURSIVE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief mtime
|
||||
|
|
|
@ -1493,6 +1493,43 @@ static void JS_MakeDirectory (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_V8_RETURN_UNDEFINED();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief creates a directory
|
||||
/// @startDocuBlock JS_MakeDirectoryRecursive
|
||||
/// `fs.makeDirectoryRecursive(path)`
|
||||
///
|
||||
/// Creates the directory hierarchy specified by *path*.
|
||||
/// @endDocuBlock
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void JS_MakeDirectoryRecursive (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
v8::Isolate* isolate = args.GetIsolate();
|
||||
v8::HandleScope scope(isolate);
|
||||
|
||||
// 2nd argument (permissions) are ignored for now
|
||||
|
||||
// extract arguments
|
||||
if (args.Length() != 1 && args.Length() != 2) {
|
||||
TRI_V8_THROW_EXCEPTION_USAGE("makeDirectoryRecursive(<path>)");
|
||||
}
|
||||
|
||||
TRI_Utf8ValueNFC name(TRI_UNKNOWN_MEM_ZONE, args[0]);
|
||||
|
||||
if (*name == nullptr) {
|
||||
TRI_V8_THROW_TYPE_ERROR("<path> must be a string");
|
||||
}
|
||||
long systemError = 0;
|
||||
std::string systemErrorStr;
|
||||
int res = TRI_CreateRecursiveDirectory(*name, systemError, systemErrorStr);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
TRI_V8_THROW_EXCEPTION_MESSAGE(res, systemErrorStr);
|
||||
}
|
||||
|
||||
TRI_V8_RETURN_UNDEFINED();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief unzips a file
|
||||
/// @startDocuBlock JS_Unzip
|
||||
|
@ -4247,6 +4284,7 @@ void TRI_InitV8Utils (v8::Isolate* isolate,
|
|||
TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("FS_LIST"), JS_List);
|
||||
TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("FS_LIST_TREE"), JS_ListTree);
|
||||
TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("FS_MAKE_DIRECTORY"), JS_MakeDirectory);
|
||||
TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("FS_MAKE_DIRECTORY_RECURSIVE"), JS_MakeDirectoryRecursive);
|
||||
TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("FS_MOVE"), JS_MoveFile);
|
||||
TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("FS_MTIME"), JS_MTime);
|
||||
TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("FS_REMOVE"), JS_Remove);
|
||||
|
|
Loading…
Reference in New Issue