From 3f7bdfd702e47e7063c5fc31a1279c3cd3065fce Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 14 Aug 2017 10:03:13 -0300 Subject: Make safeUnlink safer --- src/playlist-utils.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/playlist-utils.js b/src/playlist-utils.js index 765a317..479b0c5 100644 --- a/src/playlist-utils.js +++ b/src/playlist-utils.js @@ -293,7 +293,7 @@ function isTrack(obj) { // return typeof array[1] === 'string' } -function safeUnlink(file, playlist) { +async function safeUnlink(file, playlist) { if (!playlist) { throw new Error('No playlist given to safe-unlink.') } @@ -311,7 +311,21 @@ function safeUnlink(file, playlist) { ) } - return unlink(file) + try { + await unlink(file) + } catch(err) { + if (err.code === 'ENOENT') { + console.trace( + `Attempted to delete file "${file}" which does not exist. This ` + + 'could be because of a temporary file being automatically deleted ' + + 'by the system before now, or because of http-music attempting to ' + + 'delete a temporary file which it has already deleted; otherwise ' + + 'this is almost certainly a bug.' + ) + } else { + throw err + } + } } module.exports = { -- cgit 1.3.0-6-gf8a5