Skip to content

Commit

Permalink
fix(uninstall): ensure uninstall succeeds if using ghost user
Browse files Browse the repository at this point in the history
no issue
- with the permissions change in #296, the ownership of the ghost directory was changed. Because of this we need to sudo remove the directory on uninstall
  • Loading branch information
acburdine committed Jul 6, 2017
1 parent ba54099 commit f6a34a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
10 changes: 10 additions & 0 deletions extensions/linux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class LinuxExtension extends cli.Extension {
task: () => this.ui.sudo(`chown -R ghost:ghost ${path.join(ctx.instance.dir, 'content')}`)
}], false);
}

uninstall(instance) {
if (os.platform() !== 'linux') {
return Promise.resolve();
}

// because we have changed the ownership of the ghost content folder,
// we need to remove it manually here via sudo
return this.ui.sudo(`rm -rf ${path.join(instance.dir, 'content')}`);
}
}

module.exports = LinuxExtension;
41 changes: 24 additions & 17 deletions lib/commands/uninstall.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const fs = require('fs-extra');
const path = require('path');

const StopCommand = require('./stop');
const Command = require('../command');
Expand Down Expand Up @@ -27,23 +28,29 @@ class UninstallCommand extends Command {
return Promise.reject(false);
}

if (!instance.running) {
return Promise.resolve();
}

instance.loadRunningEnvironment(true);

// If the instance is currently running we need to make
// sure it gets stopped
return this.runCommand(StopCommand);
}).then(() => {
this.system.setEnvironment(!fs.existsSync('config.production.json'));

return this.ui.run(this.system.hook('uninstall', instance), 'Removing related configuration');
}).then(() => this.ui.run(() => {
this.system.removeInstance(instance);
return Promise.all(fs.readdirSync('.').map(file => fs.remove(file)));
}, 'Removing Ghost installation'));
return this.ui.listr([{
title: 'Stopping Ghost',
skip: () => !instance.running,
task: () => {
instance.loadRunningEnvironment(true);
// If the instance is currently running we need to make
// sure it gets stopped
return this.runCommand(StopCommand, {quiet: true});
}
}, {
title: 'Removing related configuration',
task: () => {
this.system.setEnvironment(!fs.existsSync(path.join(instance.dir, 'config.production.json')));
return this.system.hook('uninstall', instance);
}
}, {
title: 'Removing Ghost installation',
task: () => {
this.system.removeInstance(instance);
return Promise.all(fs.readdirSync('.').map(file => fs.remove(file)));
}
}]);
});
}
}

Expand Down

0 comments on commit f6a34a8

Please sign in to comment.