Skip to content

Commit 7e38ef2

Browse files
committed
"rush purge --unsafe" should delete the ~/.rush folder
1 parent a8aa104 commit 7e38ef2

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎apps/rush-lib/src/logic/InstallManager.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ export class InstallManager {
10101010

10111011
private _queryIfReleaseIsPublished(registryUrl: string): Promise<boolean> {
10121012
let queryUrl: string = registryUrl;
1013-
if (queryUrl[- 1] !== '/') {
1013+
if (queryUrl[-1] !== '/') {
10141014
queryUrl += '/';
10151015
}
10161016
// Note that the "@" symbol does not normally get URL-encoded

‎apps/rush-lib/src/logic/PurgeManager.ts‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)