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 { ...@@ -106,8 +106,12 @@ export class AppService extends ConsoleLogger {
this.log(`Moving files.`); this.log(`Moving files.`);
for (const file of files) { for (const file of files) {
file.branchId = checkoutResult.branchId; 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.`); this.log(`Committing files.`);
await this.git await this.git
.add(files.map((f) => f.filename)) .add(files.map((f) => f.filename))
...@@ -121,13 +125,15 @@ export class AppService extends ConsoleLogger { ...@@ -121,13 +125,15 @@ export class AppService extends ConsoleLogger {
} }
} catch (e) { } catch (e) {
this.error(`Errored processing files: ${e.toString()}`); this.error(`Errored processing files: ${e.toString()}`);
const filesToDelete: string[] = [];
for (const file of files) { for (const file of files) {
try { filesToDelete.push(file.savePath);
await fs.unlink(file.savePath); filesToDelete.push(path.join(this.repoPath, file.filename));
await fs.unlink(path.join(this.repoPath, file.filename));
} catch (e) {}
file.reject(new ReturnMessageDto(500, 'upload failed').toException()); file.reject(new ReturnMessageDto(500, 'upload failed').toException());
} }
try {
await Promise.all(filesToDelete.map((path) => fs.unlink(path)));
} catch (e) {}
} finally { } finally {
for (const file of files) { for (const file of files) {
this.queueHashmap.delete(file.filename); 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