From 7bba3d91c4fa6424bd3ae0c35f5166bd2c9dd56a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 25 Sep 2020 17:17:13 +0200 Subject: [PATCH] Incorrect cleanup of directories --- src/blacklist-index.ts | 53 +++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/src/blacklist-index.ts b/src/blacklist-index.ts index 5c233da..9b9ade4 100644 --- a/src/blacklist-index.ts +++ b/src/blacklist-index.ts @@ -9,10 +9,7 @@ const fsUnlink = promisify(fs.unlink); const fsWriteFile = promisify(fs.writeFile); export class BlacklistIndex { - constructor( - protected readonly now: Date, - protected readonly outDir: string, - ) {} + constructor(protected readonly now: Date, protected readonly outDir: string) {} public async rebuild(): Promise { const validDates: string[] = []; @@ -29,10 +26,7 @@ export class BlacklistIndex { await Promise.all( (await fsReaddir(this.outDir)).map( async (directory: string): Promise => { - if ( - /^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/.exec(directory) && - (await fsStat(path.join(this.outDir, directory))).isDirectory() - ) { + if (/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/.exec(directory) && (await fsStat(path.join(this.outDir, directory))).isDirectory()) { if (validDates.indexOf(directory) === -1) { removeDirectories.push(directory); @@ -47,8 +41,8 @@ export class BlacklistIndex { if (file === 'full.json' || /^delta\-[1-4]\.json$/) { files.push(file); } - }, - ), + } + ) ); if (files.length) { @@ -64,27 +58,22 @@ export class BlacklistIndex { }); } } - }, - ), + } + ) ); - data = data.sort( - (a: IBlacklistIndexEntry, b: IBlacklistIndexEntry): number => { - const aTime = new Date(a.date).getTime(); - const bTime = new Date(b.date).getTime(); + data = data.sort((a: IBlacklistIndexEntry, b: IBlacklistIndexEntry): number => { + const aTime = new Date(a.date).getTime(); + const bTime = new Date(b.date).getTime(); - if (aTime === bTime) { - return 0; - } else { - return aTime > bTime ? -1 : 1; - } - }, - ); + if (aTime === bTime) { + return 0; + } else { + return aTime > bTime ? -1 : 1; + } + }); - await fsWriteFile( - path.join(this.outDir, 'index.json'), - JSON.stringify(data, null, 2), - ); + await fsWriteFile(path.join(this.outDir, 'index.json'), JSON.stringify(data, null, 2)); await this.cleanup(removeDirectories); } @@ -95,16 +84,16 @@ export class BlacklistIndex { async (directory: string): Promise => { const dirPath = path.join(this.outDir, directory); await Promise.all( - (await fsReaddir(directory)).map( + (await fsReaddir(dirPath)).map( async (file: string): Promise => { await fsUnlink(path.join(dirPath, file)); - }, - ), + } + ) ); await fsRmdir(dirPath); - }, - ), + } + ) ); } } -- 2.20.1