Commit 813ffda1 authored by nanahira's avatar nanahira

use promise.all for fs operations

parent 908a3b3c
Pipeline #5763 passed with stages
in 32 minutes and 25 seconds
......@@ -106,8 +106,12 @@ export class AppService extends ConsoleLogger {
this.log(`Moving files.`);
for (const file of files) {
file.branchId = checkoutResult.branchId;
await fs.rename(file.savePath, path.join(this.repoPath, file.filename));
}
await Promise.all(
files.map((file) =>
fs.rename(file.savePath, path.join(this.repoPath, file.filename)),
),
);
this.log(`Committing files.`);
await this.git
.add(files.map((f) => f.filename))
......@@ -121,13 +125,15 @@ export class AppService extends ConsoleLogger {
}
} catch (e) {
this.error(`Errored processing files: ${e.toString()}`);
const filesToDelete: string[] = [];
for (const file of files) {
try {
await fs.unlink(file.savePath);
await fs.unlink(path.join(this.repoPath, file.filename));
} catch (e) {}
filesToDelete.push(file.savePath);
filesToDelete.push(path.join(this.repoPath, file.filename));
file.reject(new ReturnMessageDto(500, 'upload failed').toException());
}
try {
await Promise.all(filesToDelete.map((path) => fs.unlink(path)));
} catch (e) {}
} finally {
for (const file of files) {
this.queueHashmap.delete(file.filename);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment