1
0
Fork 0

Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel

This commit is contained in:
Frank Celler 2013-03-24 15:03:16 +01:00
commit 0a488cd84b
14 changed files with 176 additions and 17 deletions

View File

@ -176,6 +176,7 @@ ArangoServer::ArangoServer (int argc, char** argv)
: _argc(argc),
_argv(argv),
_binaryPath(),
_tempPath(),
_applicationScheduler(0),
_applicationDispatcher(0),
_applicationEndpointServer(0),
@ -196,7 +197,10 @@ ArangoServer::ArangoServer (int argc, char** argv)
p = TRI_LocateBinaryPath(argv[0]);
_binaryPath = p;
TRI_FreeString(TRI_CORE_MEM_ZONE, p);
p = TRI_GetTempPath();
_tempPath = string(p);
TRI_FreeString(TRI_CORE_MEM_ZONE, p);
// set working directory and database directory
@ -252,7 +256,7 @@ void ArangoServer::buildApplicationServer () {
// V8 engine
// .............................................................................
_applicationV8 = new ApplicationV8(_binaryPath);
_applicationV8 = new ApplicationV8(_binaryPath, _tempPath);
_applicationServer->addFeature(_applicationV8);
// .............................................................................
@ -299,6 +303,7 @@ void ArangoServer::buildApplicationServer () {
additional[ApplicationServer::OPTIONS_CMDLINE]
("console", "do not start as server, start a JavaScript emergency console instead")
("temp-path", &_tempPath, "temporary path")
("upgrade", "perform a database upgrade")
;

View File

@ -213,6 +213,12 @@ namespace triagens {
std::string _binaryPath;
////////////////////////////////////////////////////////////////////////////////
/// @brief temporary path
////////////////////////////////////////////////////////////////////////////////
std::string _tempPath;
////////////////////////////////////////////////////////////////////////////////
/// @brief application scheduler
////////////////////////////////////////////////////////////////////////////////

View File

@ -166,8 +166,9 @@ void ApplicationV8::V8Context::handleGlobalContextMethods () {
/// @brief constructor
////////////////////////////////////////////////////////////////////////////////
ApplicationV8::ApplicationV8 (string const& binaryPath)
ApplicationV8::ApplicationV8 (string const& binaryPath, string const& tempPath)
: ApplicationFeature("V8"),
_tempPath(tempPath),
_startupPath(),
_modulesPath(),
_packagePath(),
@ -715,7 +716,7 @@ bool ApplicationV8::prepareV8Instance (const size_t i) {
}
TRI_InitV8Conversions(context->_context);
TRI_InitV8Utils(context->_context, _modulesPath, _packagePath);
TRI_InitV8Utils(context->_context, _modulesPath, _packagePath, _tempPath);
TRI_InitV8Shell(context->_context);
{

View File

@ -167,7 +167,7 @@ namespace triagens {
/// @brief constructor
////////////////////////////////////////////////////////////////////////////////
ApplicationV8 (string const& binaryPath);
ApplicationV8 (string const&, string const&);
////////////////////////////////////////////////////////////////////////////////
/// @brief destructor
@ -339,6 +339,12 @@ namespace triagens {
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief temporary path
////////////////////////////////////////////////////////////////////////////////
string _tempPath;
////////////////////////////////////////////////////////////////////////////////
/// @brief path to the directory containing alternate startup scripts
///

View File

@ -27,8 +27,10 @@
#include "ArangoClient.h"
#include "BasicsC/files.h"
#include "BasicsC/logging.h"
#include "BasicsC/messages.h"
#include "BasicsC/strings.h"
#include "BasicsC/terminal-utils.h"
#include "Basics/FileUtils.h"
#include "Basics/ProgramOptionsDescription.h"
@ -92,6 +94,7 @@ char const * ArangoClient::PROMPT_IGNORE_END = "\002";
ArangoClient::ArangoClient ()
: _configFile(),
_tempPath(),
_logLevel("info"),
_quiet(false),
@ -121,6 +124,13 @@ ArangoClient::ArangoClient ()
_hasPassword(false),
_connectTimeout(DEFAULT_CONNECTION_TIMEOUT),
_requestTimeout(DEFAULT_REQUEST_TIMEOUT) {
char* p = TRI_GetTempPath();
if (p != NULL) {
_tempPath = string(p);
TRI_Free(TRI_CORE_MEM_ZONE, p);
}
}
////////////////////////////////////////////////////////////////////////////////
@ -150,6 +160,7 @@ void ArangoClient::setupGeneral (ProgramOptionsDescription& description) {
description
("configuration,c", &_configFile, "read configuration file")
("help,h", "help message")
("temp-path", &_tempPath, "path for temporary files")
("quiet,s", "no banner")
(loggingOptions, false)
;
@ -657,6 +668,14 @@ void ArangoClient::setUsePager (bool value) {
_usePager = value;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief gets the temporary path
////////////////////////////////////////////////////////////////////////////////
string const& ArangoClient::tempPath () const {
return _tempPath;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief gets endpoint to connect to as string
////////////////////////////////////////////////////////////////////////////////

View File

@ -325,6 +325,12 @@ namespace triagens {
void setUsePager (bool);
////////////////////////////////////////////////////////////////////////////////
/// @brief gets the temporary path
////////////////////////////////////////////////////////////////////////////////
string const& tempPath () const;
////////////////////////////////////////////////////////////////////////////////
/// @brief gets endpoint to connect to as string
////////////////////////////////////////////////////////////////////////////////
@ -386,6 +392,12 @@ namespace triagens {
string _configFile;
////////////////////////////////////////////////////////////////////////////////
/// @brief temporary path
////////////////////////////////////////////////////////////////////////////////
string _tempPath;
////////////////////////////////////////////////////////////////////////////////
/// @brief log level
////////////////////////////////////////////////////////////////////////////////

View File

@ -1399,7 +1399,7 @@ int main (int argc, char* argv[]) {
// add function SYS_OUTPUT to use pager
TRI_AddGlobalVariableVocbase(context, "SYS_OUTPUT", v8::FunctionTemplate::New(JS_PagerOutput)->GetFunction());
TRI_InitV8Utils(context, StartupModules, StartupNodeModules);
TRI_InitV8Utils(context, StartupModules, StartupNodeModules, BaseClient.tempPath());
TRI_InitV8Shell(context);
// reset the prompt error flag (will determine prompt colors)

View File

@ -1,8 +1,8 @@
/*jslint indent: 2, nomen: true, maxlen: 120, sloppy: true, vars: true, white: true, plusplus: true, nonpropdel: true, proto: true */
/*global require, module, Module, FS_MOVE, FS_REMOVE, FS_EXISTS, FS_IS_DIRECTORY, FS_IS_FILE,
FS_LIST_TREE, FS_UNZIP_FILE, FS_ZIP_FILE, SYS_DOWNLOAD, SYS_SEND_FILE,
SYS_EXECUTE, SYS_LOAD, SYS_LOG, SYS_LOG_LEVEL, SYS_MD5, SYS_OUTPUT, SYS_PROCESS_STAT, SYS_RAND,
SYS_READ, SYS_SPRINTF, SYS_TIME, SYS_START_PAGER, SYS_STOP_PAGER, SYS_SHA256, SYS_WAIT,
FS_GET_TEMP_FILE, FS_GET_TEMP_PATH, FS_LIST_TREE, FS_UNZIP_FILE, FS_ZIP_FILE, SYS_DOWNLOAD,
SYS_SEND_FILE, SYS_EXECUTE, SYS_LOAD, SYS_LOG, SYS_LOG_LEVEL, SYS_MD5, SYS_OUTPUT, SYS_PROCESS_STAT,
SYS_RAND, SYS_READ, SYS_SPRINTF, SYS_TIME, SYS_START_PAGER, SYS_STOP_PAGER, SYS_SHA256, SYS_WAIT,
SYS_GETLINE, SYS_PARSE, SYS_SAVE, SYS_IMPORT_CSV_FILE, SYS_IMPORT_JSON_FILE, PACKAGE_PATH,
SYS_GEN_RANDOM_NUMBERS, SYS_GEN_RANDOM_ALPHA_NUMBERS, SYS_GEN_RANDOM_SALT, SYS_CREATE_NONCE,
SYS_CHECK_AND_MARK_NONCE, SYS_REQUEST_STATISTICS,
@ -178,6 +178,16 @@
internal.exists = FS_EXISTS;
delete FS_EXISTS;
}
if (typeof FS_GET_TEMP_PATH !== "undefined") {
internal.getTempPath = FS_GET_TEMP_PATH;
delete FS_GET_TEMP_PATH;
}
if (typeof FS_GET_TEMP_FILE !== "undefined") {
internal.getTempFile = FS_GET_TEMP_FILE;
delete FS_GET_TEMP_FILE;
}
if (typeof FS_IS_DIRECTORY !== "undefined") {
internal.isDirectory = FS_IS_DIRECTORY;

View File

@ -51,6 +51,18 @@
fs.exists = internal.exists;
////////////////////////////////////////////////////////////////////////////////
/// @brief returns a temporary file
////////////////////////////////////////////////////////////////////////////////
fs.getTempFile = internal.getTempFile;
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the temporary path
////////////////////////////////////////////////////////////////////////////////
fs.getTempPath = internal.getTempPath;
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the home directory
////////////////////////////////////////////////////////////////////////////////

View File

@ -1,8 +1,8 @@
/*jslint indent: 2, nomen: true, maxlen: 120, sloppy: true, vars: true, white: true, plusplus: true, nonpropdel: true, proto: true */
/*global require, module, Module, FS_MOVE, FS_REMOVE, FS_EXISTS, FS_IS_DIRECTORY, FS_IS_FILE,
FS_LIST_TREE, FS_UNZIP_FILE, FS_ZIP_FILE, SYS_DOWNLOAD, SYS_SEND_FILE,
SYS_EXECUTE, SYS_LOAD, SYS_LOG, SYS_LOG_LEVEL, SYS_MD5, SYS_OUTPUT, SYS_PROCESS_STAT, SYS_RAND,
SYS_READ, SYS_SPRINTF, SYS_TIME, SYS_START_PAGER, SYS_STOP_PAGER, SYS_SHA256, SYS_WAIT,
FS_GET_TEMP_FILE, FS_GET_TEMP_PATH, FS_LIST_TREE, FS_UNZIP_FILE, FS_ZIP_FILE, SYS_DOWNLOAD,
SYS_SEND_FILE, SYS_EXECUTE, SYS_LOAD, SYS_LOG, SYS_LOG_LEVEL, SYS_MD5, SYS_OUTPUT, SYS_PROCESS_STAT,
SYS_RAND, SYS_READ, SYS_SPRINTF, SYS_TIME, SYS_START_PAGER, SYS_STOP_PAGER, SYS_SHA256, SYS_WAIT,
SYS_GETLINE, SYS_PARSE, SYS_SAVE, SYS_IMPORT_CSV_FILE, SYS_IMPORT_JSON_FILE, PACKAGE_PATH,
SYS_GEN_RANDOM_NUMBERS, SYS_GEN_RANDOM_ALPHA_NUMBERS, SYS_GEN_RANDOM_SALT, SYS_CREATE_NONCE,
SYS_CHECK_AND_MARK_NONCE, SYS_REQUEST_STATISTICS,
@ -178,6 +178,16 @@
internal.exists = FS_EXISTS;
delete FS_EXISTS;
}
if (typeof FS_GET_TEMP_PATH !== "undefined") {
internal.getTempPath = FS_GET_TEMP_PATH;
delete FS_GET_TEMP_PATH;
}
if (typeof FS_GET_TEMP_FILE !== "undefined") {
internal.getTempFile = FS_GET_TEMP_FILE;
delete FS_GET_TEMP_FILE;
}
if (typeof FS_IS_DIRECTORY !== "undefined") {
internal.isDirectory = FS_IS_DIRECTORY;

View File

@ -13,7 +13,7 @@ function CreateFoxxApplicationSpec () {
routingInfo = app.routingInfo;
assertEqual(routingInfo.routes.length, 0);
assertUndefined(routingInfo.urlPrefix);
assertEqual(routingInfo.urlPrefix, "");
},
testCreationWithURLPrefix: function () {

View File

@ -1606,9 +1606,9 @@ int TRI_Crc32File (char const* path, uint32_t* crc) {
char* TRI_GetTempPath () {
#ifdef _WIN32
#warning TRI_GetTempPath not implemented for Windows
return NULL;
return TRI_DuplicateString(".");
#else
return "/tmp/arangodb";
return TRI_DuplicateString("/tmp/arangodb");
#endif
}
@ -1618,9 +1618,18 @@ char* TRI_GetTempPath () {
int TRI_GetTempName (char const* directory, char** result) {
char* dir;
char* temp;
int tries;
dir = TRI_Concatenate2File(TRI_GetTempPath(), directory);
temp = TRI_GetTempPath();
if (directory != NULL) {
dir = TRI_Concatenate2File(temp, directory);
}
else {
dir = TRI_DuplicateString(temp);
}
TRI_Free(TRI_CORE_MEM_ZONE, temp);
TRI_CreateRecursiveDirectory(dir);

View File

@ -819,6 +819,63 @@ static v8::Handle<v8::Value> JS_Getline (v8::Arguments const& argv) {
return scope.Close(v8::String::New(line.c_str(), line.size()));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return the temporary directory
///
/// @FUN{fs.getTempPath()}
///
/// Returns the absolute path of the temporary directory
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_GetTempPath (v8::Arguments const& argv) {
v8::HandleScope scope;
if (argv.Length() != 0) {
return scope.Close(v8::ThrowException(v8::String::New("usage: getTempPath()")));
}
// return result
return scope.Close(v8::String::New(TempPath.c_str(), TempPath.size()));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return the name for a (new) temporary file
///
/// @FUN{fs.getTempFile(@FA{directory})}
///
/// Returns the name for a new temporary file in directory @FA{directory}.
/// An empty file will be created so no other process can create a file of the
/// same name.
///
/// Note that the directory @FA{directory} must exist.
////////////////////////////////////////////////////////////////////////////////
static v8::Handle<v8::Value> JS_GetTempFile (v8::Arguments const& argv) {
v8::HandleScope scope;
if (argv.Length() > 1) {
return scope.Close(v8::ThrowException(v8::String::New("usage: getTempFile(<directory>)")));
}
const char* p = NULL;
string path;
if (argv.Length() == 1) {
path = TRI_ObjectToString(argv[0]);
p = path.c_str();
}
char* result = 0;
if (TRI_GetTempName(p, &result) != TRI_ERROR_NO_ERROR) {
return scope.Close(v8::ThrowException(CreateErrorObject(TRI_ERROR_INTERNAL, "could not create temp file")));
}
const string tempfile(result);
TRI_Free(TRI_CORE_MEM_ZONE, result);
// return result
return scope.Close(v8::String::New(tempfile.c_str(), tempfile.size()));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief tests if path is a directory
///
@ -2200,7 +2257,8 @@ v8::Handle<v8::Array> TRI_V8PathList (string const& modules) {
void TRI_InitV8Utils (v8::Handle<v8::Context> context,
string const& modules,
string const& nodes) {
string const& nodes,
string const& tempPath) {
v8::HandleScope scope;
v8::Handle<v8::FunctionTemplate> ft;
@ -2217,11 +2275,15 @@ void TRI_InitV8Utils (v8::Handle<v8::Context> context,
isolate->SetData(v8g);
}
TempPath = tempPath;
// .............................................................................
// create the global functions
// .............................................................................
TRI_AddGlobalFunctionVocbase(context, "FS_EXISTS", JS_Exists);
TRI_AddGlobalFunctionVocbase(context, "FS_GET_TEMP_FILE", JS_GetTempFile);
TRI_AddGlobalFunctionVocbase(context, "FS_GET_TEMP_PATH", JS_GetTempPath);
TRI_AddGlobalFunctionVocbase(context, "FS_IS_DIRECTORY", JS_IsDirectory);
TRI_AddGlobalFunctionVocbase(context, "FS_IS_FILE", JS_IsFile);
TRI_AddGlobalFunctionVocbase(context, "FS_LIST_TREE", JS_ListTree);

View File

@ -79,7 +79,13 @@ class TRI_Utf8ValueNFC {
/// @{
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// @brief temporary path
////////////////////////////////////////////////////////////////////////////////
static std::string TempPath;
///////////////////////////////////////////////////////////////////////////////
/// @brief slot for a type
////////////////////////////////////////////////////////////////////////////////
@ -218,7 +224,8 @@ v8::Handle<v8::Array> TRI_V8PathList (std::string const& modules);
void TRI_InitV8Utils (v8::Handle<v8::Context>,
std::string const& modules,
std::string const& nodes);
std::string const& nodes,
std::string const& tempPath);
////////////////////////////////////////////////////////////////////////////////
/// @}