1
1
'use strict' ;
2
2
const fs = require ( 'fs-extra' ) ;
3
+ const os = require ( 'os' ) ;
3
4
const path = require ( 'path' ) ;
4
5
const fkill = require ( 'fkill' ) ;
5
6
const spawn = require ( 'child_process' ) . spawn ;
@@ -28,6 +29,14 @@ class LocalProcess extends ProcessManager {
28
29
* @public
29
30
*/
30
31
start ( cwd , environment ) {
32
+ const stat = fs . lstatSync ( path . join ( cwd , 'content' ) ) ;
33
+
34
+ // Check that content folder is owned by the current user
35
+ if ( stat . uid !== process . getuid ( ) ) {
36
+ return Promise . reject ( new errors . SystemError ( `The content folder is not owned by the current user.
37
+ Please ensure the content folder has correct permissions and try again.` ) ) ;
38
+ }
39
+
31
40
return new Promise ( ( resolve , reject ) => {
32
41
const cp = spawn ( 'node' , [ process . argv [ 1 ] , 'run' ] , {
33
42
cwd : cwd ,
@@ -39,7 +48,12 @@ class LocalProcess extends ProcessManager {
39
48
// Stick the pid into the pidfile so we can stop the process later
40
49
fs . writeFileSync ( path . join ( cwd , PID_FILE ) , cp . pid ) ;
41
50
42
- cp . on ( 'error' , reject ) ;
51
+ cp . on ( 'error' , ( error ) => {
52
+ reject ( new errors . CliError ( {
53
+ message : 'An error occurred while starting Ghost.' ,
54
+ err : error
55
+ } ) ) ;
56
+ } ) ;
43
57
44
58
cp . on ( 'exit' , ( code ) => {
45
59
fs . removeSync ( path . join ( cwd , PID_FILE ) ) ;
@@ -50,8 +64,7 @@ class LocalProcess extends ProcessManager {
50
64
cp . on ( 'message' , ( msg ) => {
51
65
if ( msg . error ) {
52
66
fs . removeSync ( path . join ( cwd , PID_FILE ) ) ;
53
-
54
- return reject ( new errors . GhostError ( msg ) ) ;
67
+ return reject ( new errors . GhostError ( msg . error ) ) ;
55
68
}
56
69
57
70
if ( msg . started ) {
@@ -80,18 +93,24 @@ class LocalProcess extends ProcessManager {
80
93
} catch ( e ) {
81
94
if ( e . code === 'ENOENT' ) {
82
95
// pid was not found, exit
83
- return ;
96
+ return Promise . resolve ( ) ;
84
97
}
85
98
86
- throw e ;
99
+ return Promise . reject ( new errors . CliError ( {
100
+ message : 'An unexpected error occurred when reading the pidfile.' ,
101
+ error : e
102
+ } ) ) ;
87
103
}
88
104
89
- const isWindows = process . platform === 'win32' ;
105
+ const isWindows = os . platform ( ) === 'win32' ;
90
106
91
107
return fkill ( pid , { force : isWindows } ) . catch ( ( error ) => {
92
108
// TODO: verify windows outputs same error message as mac/linux
93
109
if ( ! error . message . match ( / N o s u c h p r o c e s s / ) ) {
94
- throw error ;
110
+ return Promise . reject ( new errors . CliError ( {
111
+ message : 'An unexpected error occurred while stopping Ghost.' ,
112
+ err : error
113
+ } ) ) ;
95
114
}
96
115
} ) . then ( ( ) => {
97
116
fs . removeSync ( path . join ( cwd , PID_FILE ) ) ;
0 commit comments