mirror of https://gitee.com/bigwinds/arangodb
added purge()
This commit is contained in:
parent
a20db01143
commit
cc5ae9d1bc
|
@ -109,6 +109,12 @@ exports.checkRequestResult = function (requestResult) {
|
|||
|
||||
throw new ArangoError(requestResult);
|
||||
}
|
||||
|
||||
var copy = requestResult._shallowCopy;
|
||||
|
||||
delete copy.error;
|
||||
|
||||
return copy;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -241,6 +241,25 @@ actions.defineHttp({
|
|||
})
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief purgesp a FOXX application
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
actions.defineHttp({
|
||||
url : "_admin/foxx/purge",
|
||||
context : "admin",
|
||||
prefix : false,
|
||||
|
||||
callback: easyPostCallback({
|
||||
body: true,
|
||||
callback: function (body) {
|
||||
var name = body.name;
|
||||
|
||||
return foxxManager.purge(name);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- END-OF-FILE
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -587,14 +587,14 @@ exports.run = function (args) {
|
|||
exports.teardown(args[1]);
|
||||
}
|
||||
else if (type === 'unmount') {
|
||||
res = exports.unmount(args[1]);
|
||||
exports.unmount(args[1]);
|
||||
}
|
||||
else if (type === 'install') {
|
||||
if (3 < args.length) {
|
||||
exports.install(args[1], args[2], JSON.parse(args[3]));
|
||||
res = exports.install(args[1], args[2], JSON.parse(args[3]));
|
||||
}
|
||||
else {
|
||||
exports.install(args[1], args[2]);
|
||||
res = exports.install(args[1], args[2]);
|
||||
}
|
||||
|
||||
printf("Application %s installed successfully at mount point %s\n",
|
||||
|
@ -608,6 +608,13 @@ exports.run = function (args) {
|
|||
res.appId,
|
||||
res.mount);
|
||||
}
|
||||
else if (type === 'purge') {
|
||||
res = exports.purge(args[1]);
|
||||
|
||||
printf("Application %s and %d mounts purged successfully\n",
|
||||
res.name,
|
||||
res.purged.length);
|
||||
}
|
||||
else if (type === 'list') {
|
||||
if (1 < args.length && args[1] === "prefix") {
|
||||
exports.list(true);
|
||||
|
@ -887,6 +894,22 @@ exports.uninstall = function (mount) {
|
|||
return exports.unmount(mount);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief purges a FOXX application
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.purge = function (key) {
|
||||
'use strict';
|
||||
|
||||
var req = {
|
||||
name: key
|
||||
};
|
||||
|
||||
var res = arango.POST("/_admin/foxx/purge", JSON.stringify(req));
|
||||
|
||||
return arangosh.checkRequestResult(res);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns all installed FOXX applications
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1225,6 +1248,7 @@ exports.help = function () {
|
|||
"teardown" : "teardown execute the teardown script (app must be still be mounted)",
|
||||
"unmount" : "unmounts a mounted foxx application",
|
||||
"uninstall" : "unmounts a mounted foxx application and calls its teardown method",
|
||||
"purge" : "physically removes a foxx application and all mounts",
|
||||
"list" : "lists all installed foxx applications",
|
||||
"fetched" : "lists all fetched foxx applications that were fetched into the local repository",
|
||||
"available" : "lists all foxx applications available in the local repository",
|
||||
|
|
|
@ -41,6 +41,41 @@ function FoxxManagerSuite () {
|
|||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test update
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testUpdate : function () {
|
||||
fm.update();
|
||||
|
||||
var result = fm.availableJson();
|
||||
var i, n;
|
||||
|
||||
n = result.length;
|
||||
assertTrue(n > 0);
|
||||
|
||||
// validate the results structure
|
||||
for (i = 0; i < n; ++i) {
|
||||
var entry = result[i];
|
||||
|
||||
assertTrue(entry.hasOwnProperty("description"));
|
||||
assertTrue(entry.hasOwnProperty("name"));
|
||||
assertTrue(entry.hasOwnProperty("author"));
|
||||
assertTrue(entry.hasOwnProperty("latestVersion"));
|
||||
}
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test available
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
testFetch : function () {
|
||||
fm.update();
|
||||
fm.purge("itzpapalotl");
|
||||
|
||||
fm.fetch("github", "jsteemann/itzpapalotl");
|
||||
},
|
||||
*/
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test search
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -99,7 +134,9 @@ function FoxxManagerSuite () {
|
|||
/// @brief test install
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testInstall : function () {
|
||||
testInstallSingle : function () {
|
||||
fm.update();
|
||||
|
||||
try {
|
||||
fm.uninstall("/itz");
|
||||
}
|
||||
|
@ -107,15 +144,84 @@ function FoxxManagerSuite () {
|
|||
}
|
||||
|
||||
fm.install("itzpapalotl", "/itz");
|
||||
|
||||
var endpoint = arango.getEndpoint();
|
||||
endpoint = endpoint.replace(/^tcp:/g, 'http:').replace(/^ssl:/g, 'https:');
|
||||
|
||||
var url = endpoint + '/itz';
|
||||
|
||||
var url = '/itz/random';
|
||||
var fetched = arango.GET(url);
|
||||
|
||||
require("internal").print(arango.GET(url));
|
||||
assertTrue(fetched.hasOwnProperty("name"));
|
||||
|
||||
fm.uninstall("/itz");
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test install
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testInstallMulti : function () {
|
||||
fm.update();
|
||||
|
||||
try {
|
||||
fm.uninstall("/itz1");
|
||||
fm.uninstall("/itz2");
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
|
||||
fm.install("itzpapalotl", "/itz1");
|
||||
fm.install("itzpapalotl", "/itz2");
|
||||
|
||||
var url, fetched;
|
||||
|
||||
url = '/itz1/random';
|
||||
fetched = arango.GET(url);
|
||||
assertTrue(fetched.hasOwnProperty("name"));
|
||||
|
||||
url = '/itz2/random';
|
||||
fetched = arango.GET(url);
|
||||
|
||||
assertTrue(fetched.hasOwnProperty("name"));
|
||||
|
||||
fm.uninstall("/itz1");
|
||||
fm.uninstall("/itz2");
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test uninstall
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testUninstallInstalled : function () {
|
||||
fm.update();
|
||||
|
||||
try {
|
||||
fm.uninstall("/itz");
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
|
||||
fm.install("itzpapalotl", "/itz");
|
||||
fm.uninstall("/itz");
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test uninstall
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testUninstallUninstalled : function () {
|
||||
fm.update();
|
||||
|
||||
try {
|
||||
fm.uninstall("/itz");
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
|
||||
try {
|
||||
// already uninstalled
|
||||
fm.uninstall("/itz");
|
||||
fail();
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -690,7 +690,7 @@ exports.mount = function (appId, mount, options) {
|
|||
executeGlobalContextFunction("require(\"org/arangodb/actions\").reloadRouting()");
|
||||
}
|
||||
|
||||
return { appId: app._id, mountId: doc._key };
|
||||
return { appId: app._id, mountId: doc._key, mount: mount };
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -754,7 +754,7 @@ exports.teardown = function (mount) {
|
|||
/// @brief unmounts a FOXX application
|
||||
///
|
||||
/// Input:
|
||||
/// * key: mount key o mount point
|
||||
/// * key: mount key or mount point
|
||||
///
|
||||
/// Output:
|
||||
/// * appId: the application identifier
|
||||
|
@ -783,6 +783,55 @@ exports.unmount = function (mount) {
|
|||
return { appId: doc.app, mount: doc.mount, collectionPrefix: doc.collectionPrefix };
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief purges a FOXX application
|
||||
///
|
||||
/// Input:
|
||||
/// * name: application name
|
||||
///
|
||||
/// Output:
|
||||
/// * appId: the application identifier
|
||||
/// * mount: the mount path starting with "/"
|
||||
/// * collectionPrefix: the collection prefix
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.purge = function (name) {
|
||||
'use strict';
|
||||
|
||||
var doc = getStorage().firstExample({ type: "app", name: name });
|
||||
|
||||
if (doc === null) {
|
||||
throw new Error("Cannot find application '" + name + "'");
|
||||
}
|
||||
|
||||
if (doc.isSystem) {
|
||||
throw new Error("Cannot purge system application");
|
||||
}
|
||||
|
||||
var purged = [ ];
|
||||
|
||||
var cursor = getStorage().byExample({ type: "mount", name: name });
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
var mount = cursor.next();
|
||||
|
||||
exports.teardown(mount.mount);
|
||||
exports.unmount(mount.mount);
|
||||
|
||||
purged.push(mount.mount);
|
||||
}
|
||||
|
||||
// remove the app
|
||||
getStorage().remove(doc);
|
||||
|
||||
executeGlobalContextFunction("require(\"org/arangodb/actions\").reloadRouting()");
|
||||
|
||||
var path = fs.join(module.appPath(), doc.path);
|
||||
fs.removeDirectoryRecursive(path, true);
|
||||
|
||||
return { appId: doc.app, name: name, purged: purged };
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief sets up a development app
|
||||
///
|
||||
|
|
|
@ -1830,7 +1830,7 @@ static v8::Handle<v8::Value> JS_RemoveRecursiveDirectory (v8::Arguments const& a
|
|||
v8::HandleScope scope;
|
||||
|
||||
// extract the arguments
|
||||
if (argv.Length() != 1) {
|
||||
if (argv.Length() < 1) {
|
||||
TRI_V8_EXCEPTION_USAGE(scope, "removeDirectoryRecursive(<path>)");
|
||||
}
|
||||
|
||||
|
@ -1844,24 +1844,35 @@ static v8::Handle<v8::Value> JS_RemoveRecursiveDirectory (v8::Arguments const& a
|
|||
TRI_V8_EXCEPTION_PARAMETER(scope, "<path> must be a valid directory name");
|
||||
}
|
||||
|
||||
char* tempPath = TRI_GetUserTempPath();
|
||||
bool force = false;
|
||||
|
||||
if (argv.Length() > 1) {
|
||||
force = TRI_ObjectToBoolean(argv[1]);
|
||||
}
|
||||
|
||||
if (! force) {
|
||||
// check if we're inside the temp directory. force will override this check
|
||||
char* tempPath = TRI_GetUserTempPath();
|
||||
|
||||
if (tempPath == NULL || strlen(tempPath) < 6) {
|
||||
// some security measure so we don't accidently delete all our files
|
||||
if (tempPath == 0 || strlen(tempPath) < 6) {
|
||||
// some security measure so we don't accidently delete all our files
|
||||
if (tempPath != 0) {
|
||||
TRI_FreeString(TRI_CORE_MEM_ZONE, tempPath);
|
||||
}
|
||||
|
||||
TRI_V8_EXCEPTION_PARAMETER(scope, "temporary directory name is too short. will not remove directory");
|
||||
}
|
||||
|
||||
const string path(*name);
|
||||
if (! TRI_EqualString2(path.c_str(), tempPath, strlen(tempPath))) {
|
||||
TRI_FreeString(TRI_CORE_MEM_ZONE, tempPath);
|
||||
|
||||
TRI_V8_EXCEPTION_PARAMETER(scope, "directory to be removed is outside of temporary path");
|
||||
}
|
||||
|
||||
TRI_FreeString(TRI_CORE_MEM_ZONE, tempPath);
|
||||
|
||||
TRI_V8_EXCEPTION_PARAMETER(scope, "temporary directory name is too short. will not remove directory");
|
||||
}
|
||||
|
||||
const string path(*name);
|
||||
if (! TRI_EqualString2(path.c_str(), tempPath, strlen(tempPath))) {
|
||||
TRI_FreeString(TRI_CORE_MEM_ZONE, tempPath);
|
||||
|
||||
TRI_V8_EXCEPTION_PARAMETER(scope, "directory to be removed is outside of temporary path");
|
||||
}
|
||||
|
||||
TRI_FreeString(TRI_CORE_MEM_ZONE, tempPath);
|
||||
|
||||
int res = TRI_RemoveDirectory(*name);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
|
|
Loading…
Reference in New Issue