Shuffle directories when cleaning distributions

This commit is contained in:
Koen Vlaswinkel
2024-10-17 10:46:20 +02:00
parent 1843467146
commit ec5fe521b8

View File

@@ -83,6 +83,15 @@ export class ExtensionManagedDistributionCleaner {
return; return;
} }
// Shuffle the array so that multiple VS Code processes don't all try to clean up the same directory at the same time
for (let i = cleanableDirectories.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[cleanableDirectories[i], cleanableDirectories[j]] = [
cleanableDirectories[j],
cleanableDirectories[i],
];
}
void this.logger.log( void this.logger.log(
`Cleaning up ${cleanableDirectories.length} old versions of the CLI.`, `Cleaning up ${cleanableDirectories.length} old versions of the CLI.`,
); );