Skip to content

Commit 7634ef0

Browse files
fix(migrations): sudo - don't fail with existing settings folder
issue #776 In production sites, when the ghost user is used, the `content/*` folder needs to be owned by the Ghost user so the ghost application will not run into permission issues. In the migration, to make sure this happens, we run the `mkdir` command using sudo (i.e. `sudo -E -u ghost mkdir {path}`). When the Ghost user isn't needed, we use the `fs-extra` library to make sure the directory exists (specifically `ensureDirSync`). `fs.ensureDirSync` is equivilant to running `mkdir` with the `p` flag, so the behaviour between sudo and no-sudo differs. By adding the `p` flag to the sudo command, the behaviour between the two cases are equalized, and the migrations won't fail if the content/settings folder exists when the Ghost user is used.
1 parent 29f2b01 commit 7634ef0

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/migrations.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function ensureSettingsFolder(context) {
77
const contentDir = context.instance.config.get('paths.contentPath');
88

99
if (ghostUser.shouldUseGhostUser(contentDir)) {
10-
return context.ui.sudo(`mkdir ${path.resolve(contentDir, 'settings')}`, {sudoArgs: '-E -u ghost'});
10+
return context.ui.sudo(`mkdir -p ${path.resolve(contentDir, 'settings')}`, {sudoArgs: '-E -u ghost'});
1111
} else {
1212
const fs = require('fs-extra');
1313
fs.ensureDirSync(path.resolve(contentDir, 'settings'));

test/unit/migrations-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Unit: Migrations', function () {
3131
expect(ghostUserStub.calledWithExactly('/var/www/ghost/content')).to.be.true;
3232
expect(sudoStub.calledOnce).to.be.true;
3333
expect(sudoStub.calledWithExactly(
34-
'mkdir /var/www/ghost/content/settings',
34+
'mkdir -p /var/www/ghost/content/settings',
3535
{sudoArgs: '-E -u ghost'}
3636
)).to.be.true;
3737
});

0 commit comments

Comments
 (0)