Uninstallation (#211)

This commit is contained in:
Thomas Hobson 2021-04-10 16:10:18 +12:00
parent a2de8dea0c
commit 81cdc766b6
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
4 changed files with 77 additions and 5 deletions

View File

@ -131,6 +131,28 @@ class Package {
}; };
} }
async uninstall(){
logger.info(`Uninstalling ${this.language}-${this.version.raw}`);
logger.debug("Finding runtime")
const runtime = runtime.get_latest_runtime_matching_language_version(this.language, this.version.raw);
logger.debug("Unregistering runtime")
runtime.unregister();
logger.debug("Cleaning files from disk")
await fs.rmdir(this.install_path, {recursive: true})
logger.info(`Uninstalled ${this.language}-${this.version.raw}`)
return {
language: this.language,
version: this.version.raw
};
}
} }
module.exports = { module.exports = {

View File

@ -91,11 +91,33 @@ module.exports = {
// DELETE /packages/:language/:version // DELETE /packages/:language/:version
async package_uninstall(req, res) { async package_uninstall(req, res) {
return res logger.debug('Request to install package');
.status(500)
.send({ const pkg = await get_package(req.params.language, req.params.version);
message: 'Not implemented'
}); if (pkg == null) {
return res
.status(404)
.send({
message: `Requested package ${req.params.language}-${req.params.version} does not exist`
});
}
try {
const response = await pkg.uninstall();
return res
.status(200)
.send(response);
} catch(e) {
logger.error(`Error while uninstalling package ${pkg.language}-${pkg.version}:`, e.message);
return res
.status(500)
.send({
message: e.message
});
}
} }
}; };

View File

@ -63,6 +63,11 @@ class Runtime {
toString() { toString() {
return `${this.language}-${this.version.raw}`; return `${this.language}-${this.version.raw}`;
} }
unregister() {
const index = runtimes.indexOf(this);
runtimes.splice(index, 1); //Remove from runtimes list
}
} }
module.exports = runtimes; module.exports = runtimes;

View File

@ -0,0 +1,23 @@
const chalk = require('chalk');
exports.command = ['uninstall <language> <language-version>']
exports.aliases = ['u']
exports.describe = 'Installs the named package'
const msg_format = {
'color': p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Uninstallation ${p.language ? "succeeded" : "failed: " + p.message}`,
'monochrome': p => `Uninstallation ${p.language ? "succeeded" : "failed: " + p.message}`,
'json': JSON.stringify
}
exports.handler = async function({axios, language, languageVersion}){
try{
const install = await axios.delete(`/packages/${language}/${languageVersion}`)
console.log(msg_format.color(install.data));
}catch({response}){
console.error(response.data.message)
}
}