Skip to content

Commit

Permalink
Queue sftp calls per directory (pterodactyl#65)
Browse files Browse the repository at this point in the history
* use bento/ubuntu-16.04 Vagrant image

* remove unnecessary output from Vagrant provisioning

* queue sftp requests per directory

* properly call done in async sftp handlers

* Final cleanup to PR

* Fix some issues with the style stuff so the builds pass
  • Loading branch information
schrej authored and DaneEveritt committed May 26, 2018
1 parent 5f4dd9a commit 7d166d9
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .dev/vagrant/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ echo "Provisioning development environment for Pterodactyl Panel."
cp /srv/daemon/.dev/vagrant/motd.txt /etc/motd

echo "Install docker"
curl -sSL https://get.docker.com/ | sh
curl -sSL https://get.docker.com/ | sh > /dev/null
systemctl enable docker

echo "Install nodejs"
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - > /dev/null
apt-get -y install nodejs > /dev/null

echo "Install additional dependencies"
Expand Down
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.box = "bento/ubuntu-16.04"

config.vm.synced_folder "./", "/srv/daemon",
owner: "root", group: "root"
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ class Docker {
callback(err, container);
});
}],
}, (err, data) => {
}, err => {
if (err) return next(err);
return next(null, {
image: _.trimStart(config.image, '~'),
Expand Down
4 changes: 1 addition & 3 deletions src/controllers/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,7 @@ class RouteController {
Log.warn({ res_code: response.statusCode, res_body: body }, 'An error occured while attempting to retrieve file download information for an upstream provider.');
}

this.res.redirect(this.req.header('Referer') || Config.get('remote.base'), () => {
return '';
});
this.res.redirect(this.req.header('Referer') || Config.get('remote.base'), _.constant(''));
}
});
}
Expand Down
64 changes: 64 additions & 0 deletions src/helpers/sftpqueue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

/**
* Pterodactyl - Daemon
* Copyright (c) 2015 - 2018 Dane Everitt <[email protected]>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const _ = require('lodash');

class SFTPQueue {
constructor() {
this.tasks = {};
this.handlers = {};
}

push(location, task) {
if (this.handlers[location]) {
if (!_.isArray(this.tasks[location])) {
this.tasks[location] = [];
}

this.tasks[location].push(task);
} else {
this.handleTask(location, task);
}
}

handleTask(location, task) {
this.handlers[location] = true;

task(() => {
if (_.isArray(this.tasks[location]) && this.tasks[location].length > 0) {
this.handleTask(location, this.tasks[location].shift());
} else {
this.handlers[location] = false;
}
});
}

clean() {
this.tasks = {};
this.handlers = {};
}
}

module.exports = SFTPQueue;
Loading

0 comments on commit 7d166d9

Please sign in to comment.