Skip to content

Commit

Permalink
fix(tmpfile): properly remove tmp files
Browse files Browse the repository at this point in the history
  • Loading branch information
olalonde committed Oct 28, 2016
1 parent 0e2ed56 commit 1630dcf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "s3-tus-store",
"version": "1.2.2",
"version": "1.2.3",
"description": "",
"main": "./lib/index.js",
"directories": {
Expand Down
11 changes: 8 additions & 3 deletions src/write-part-by-part.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ const uploadPart = async (rs, guessedPartSize, partNumber, {
// and rewriting later when we have a new write? TODO
// PS: we always guess the size of the last part correctly
// so this is never called for the last part
tmpFile.rm() // dont need wait for this...
throw new Error(`Upload parts must be at least ${minPartSize}`)
}
// make sure temporary was file completely written to disk...
Expand All @@ -120,8 +119,6 @@ const uploadPart = async (rs, guessedPartSize, partNumber, {
tmpFileRsEos,
])

tmpFile.rm() // dont need wait for this

// TODO: put whole function in try/catch to make sure tmpfile
// remove even when errors...

Expand Down Expand Up @@ -153,6 +150,14 @@ const uploadPart = async (rs, guessedPartSize, partNumber, {
})
*/
return planA()
.catch((err) => {
tmpFile.rm() // dont need to block for this...
throw err
})
.then((result) => {
tmpFile.rm() // dont need to block for this...
return result
})
}

export default (opts = {}) => new Promise((resolve, reject) => {
Expand Down

0 comments on commit 1630dcf

Please sign in to comment.