Skip to content

Commit b5cd11d

Browse files
fix(migrations): sudo - make sure settings folder exists
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 `mkdir -p` (not `mkdir`), so the behaviour differs. By adding the `p` flag to the `mkdir` command that's run when the Ghost user is used, the behaviour between the two cases are equalized.
1 parent 464d13a commit b5cd11d

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)