Added cancel() support to File Search

This commit is contained in:
Bryan Roe 2020-11-12 17:49:22 -08:00
parent 9bebca7b97
commit 7386a3f8c2

View File

@ -2221,6 +2221,8 @@ function createMeshCore(agent) {
case 'findfile': { case 'findfile': {
// Search for files // Search for files
var r = require('file-search').find(cmd.path, cmd.filter); var r = require('file-search').find(cmd.path, cmd.filter);
if (!r.cancel) { r.cancel = function cancel() { this.child.kill(); }; }
this._search = r;
r.socket = this; r.socket = this;
r.socket.reqid = cmd.reqid; // Search request id. This is used to send responses and cancel the request. r.socket.reqid = cmd.reqid; // Search request id. This is used to send responses and cancel the request.
r.socket.path = cmd.path; // Search path r.socket.path = cmd.path; // Search path
@ -2229,9 +2231,11 @@ function createMeshCore(agent) {
break; break;
} }
case 'cancelfindfile': { case 'cancelfindfile': {
// TODO: Cancel a search for files if (this._search)
// cmd.reqid <-- Cancel this reqid {
sendConsoleText('cancelfindfile: ' + cmd.reqid); this._search.cancel();
this._search = null;
}
} }
case 'download': { case 'download': {
// Download a file // Download a file