@@ -6,6 +6,7 @@ const symlinkSync = require('symlink-or-copy').sync;
6
6
const { GhostError} = require ( '../errors' ) ;
7
7
const Command = require ( '../command' ) ;
8
8
const DoctorCommand = require ( './doctor' ) ;
9
+ const ghostUser = require ( '../utils/use-ghost-user' ) ;
9
10
10
11
class UpdateCommand extends Command {
11
12
static configureOptions ( commandName , yargs , extensions ) {
@@ -43,6 +44,7 @@ class UpdateCommand extends Command {
43
44
instance,
44
45
force,
45
46
activeVersion : instance . version ,
47
+ ui : this . ui ,
46
48
version,
47
49
zip,
48
50
v1
@@ -230,7 +232,7 @@ class UpdateCommand extends Command {
230
232
instance . nodeVersion = process . versions . node ;
231
233
}
232
234
233
- linkDefaultThemes ( { instance, rollback} ) {
235
+ async linkDefaultThemes ( { instance, rollback, ui } ) {
234
236
const currentThemesDir = path . join ( process . cwd ( ) , 'current' , 'content' , 'themes' ) ;
235
237
const contentThemesDir = path . join ( instance . config . get ( 'paths.contentPath' ) , 'themes' ) ;
236
238
// remove any broken symlinks caused by default themes no longer existing in previous version
@@ -239,7 +241,11 @@ class UpdateCommand extends Command {
239
241
const installedThemes = fs . readdirSync ( contentThemesDir ) ;
240
242
for ( const theme of installedThemes ) {
241
243
if ( ! fs . existsSync ( path . join ( contentThemesDir , theme ) ) ) {
242
- fs . rmSync ( path . join ( contentThemesDir , theme ) ) ;
244
+ if ( ghostUser . shouldUseGhostUser ( contentThemesDir ) ) {
245
+ await ui . sudo ( `rm ${ path . join ( contentThemesDir , theme ) } ` , { sudoArgs : '-E -u ghost' } ) ;
246
+ } else {
247
+ fs . unlinkSync ( path . join ( contentThemesDir , theme ) ) ;
248
+ }
243
249
}
244
250
}
245
251
}
@@ -250,10 +256,14 @@ class UpdateCommand extends Command {
250
256
const defaultThemes = fs . readdirSync ( currentThemesDir ) ;
251
257
for ( const theme of defaultThemes ) {
252
258
if ( ! fs . existsSync ( path . join ( contentThemesDir , theme ) ) ) {
253
- symlinkSync (
254
- path . join ( currentThemesDir , theme ) ,
255
- path . join ( contentThemesDir , theme )
256
- ) ;
259
+ if ( ghostUser . shouldUseGhostUser ( contentThemesDir ) ) {
260
+ await ui . sudo ( `ln -s ${ path . join ( currentThemesDir , theme ) } ${ path . join ( contentThemesDir , theme ) } ` , { sudoArgs : '-E -u ghost' } ) ;
261
+ } else {
262
+ symlinkSync (
263
+ path . join ( currentThemesDir , theme ) ,
264
+ path . join ( contentThemesDir , theme )
265
+ ) ;
266
+ }
257
267
}
258
268
}
259
269
}
0 commit comments