Skip to content

Commit

Permalink
Be sure to exit from resolved promise deleteIfExists(...) helper
Browse files Browse the repository at this point in the history
Failing to exit when the specified file path doens't exist means that we try to delete that file even though it doesn't exist. This results in a timing issue because the deletion is asynchronous. Essentially, it might unintentionally delete the file springs into being before the promise is resolved.
  • Loading branch information
DustinCampbell committed Apr 21, 2017
1 parent e7c4caa commit 0946223
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function deleteIfExists(filePath: string): Promise<void> {
.then((exists: boolean) => {
return new Promise<void>((resolve, reject) => {
if (!exists) {
resolve();
return resolve();
}

fs.unlink(filePath, err => {
Expand Down

0 comments on commit 0946223

Please sign in to comment.