@@ -56,7 +56,7 @@ export class PurgeManager {
5656 console . log ( 'Purging ' + this . _rushConfiguration . commonTempFolder ) ;
5757
5858 this . _commonTempFolderRecycler . moveAllItemsInFolder ( this . _rushConfiguration . commonTempFolder ,
59- this . _getMembersToExclude ( this . _rushConfiguration . commonTempFolder ) ) ;
59+ this . _getMembersToExclude ( this . _rushConfiguration . commonTempFolder , true ) ) ;
6060 }
6161
6262 /**
@@ -66,13 +66,22 @@ export class PurgeManager {
6666 public purgeUnsafe ( ) : void {
6767 this . purgeNormal ( ) ;
6868
69- // Also delete everything under ~/.rush/node-v4.5.6/ except for the recycler folder itself
70- console . log ( 'Purging ' + this . _rushGlobalFolder . nodeSpecificPath ) ;
69+ // We will delete everything under ~/.rush/ except for the recycler folder itself
70+ console . log ( 'Purging ' + this . _rushGlobalFolder . path ) ;
71+
72+ // If Rush itself is running under a folder such as ~/.rush/node-v4.5.6/rush-1.2.3,
73+ // we cannot delete that folder.
74+
75+ // First purge the node-specific folder, e.g. ~/.rush/node-v4.5.6/* except for rush-1.2.3:
7176 this . _rushUserFolderRecycler . moveAllItemsInFolder ( this . _rushGlobalFolder . nodeSpecificPath ,
72- this . _getMembersToExclude ( this . _rushGlobalFolder . nodeSpecificPath ) ) ;
77+ this . _getMembersToExclude ( this . _rushGlobalFolder . nodeSpecificPath , true ) ) ;
78+
79+ // Then purge the the global folder, e.g. ~/.rush/* except for node-v4.5.6
80+ this . _rushUserFolderRecycler . moveAllItemsInFolder ( this . _rushGlobalFolder . path ,
81+ this . _getMembersToExclude ( this . _rushGlobalFolder . path , false ) ) ;
7382 }
7483
75- private _getMembersToExclude ( folderToRecycle : string ) : string [ ] {
84+ private _getMembersToExclude ( folderToRecycle : string , showWarning : boolean ) : string [ ] {
7685 // Don't recycle the recycler
7786 const membersToExclude : string [ ] = [ RushConstants . rushRecyclerFolderName ] ;
7887
@@ -92,9 +101,11 @@ export class PurgeManager {
92101 if ( firstPart . length > 0 && firstPart !== '..' ) {
93102 membersToExclude . push ( firstPart ) ;
94103
95- // Warn that we won't dispose this folder
96- console . log ( colors . yellow ( 'The active process\'s folder will not be deleted: '
97- + path . join ( folderToRecycle , firstPart ) ) ) ;
104+ if ( showWarning ) {
105+ // Warn that we won't dispose this folder
106+ console . log ( colors . yellow ( 'The active process\'s folder will not be deleted: '
107+ + path . join ( folderToRecycle , firstPart ) ) ) ;
108+ }
98109 }
99110 }
100111
0 commit comments