Delete each file on failed import
This commit is contained in:
parent
e95e0463d8
commit
e37c85e933
1 changed files with 19 additions and 15 deletions
|
@ -26,7 +26,11 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
|
|||
if (torrent.files.length !== 1) {
|
||||
if (timer) clearTimeout(timer)
|
||||
|
||||
return safeWebtorrentDestroy(webtorrent, torrentId, { directoryPath, filepath: file.path }, target.torrentName)
|
||||
for (let file of torrent.files) {
|
||||
deleteDownloadedFile({ directoryPath, filepath: file.path })
|
||||
}
|
||||
|
||||
return safeWebtorrentDestroy(webtorrent, torrentId, undefined, target.torrentName)
|
||||
.then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it')))
|
||||
}
|
||||
|
||||
|
@ -79,7 +83,16 @@ function safeWebtorrentDestroy (
|
|||
}
|
||||
|
||||
// Delete downloaded file
|
||||
if (downloadedFile) {
|
||||
if (downloadedFile) deleteDownloadedFile(downloadedFile)
|
||||
|
||||
if (err) logger.warn('Cannot destroy webtorrent in timeout.', { err })
|
||||
|
||||
return res()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function deleteDownloadedFile (downloadedFile: { directoryPath: string, filepath: string }) {
|
||||
// We want to delete the base directory
|
||||
let pathToDelete = dirname(downloadedFile.filepath)
|
||||
if (pathToDelete === '.') pathToDelete = downloadedFile.filepath
|
||||
|
@ -90,12 +103,3 @@ function safeWebtorrentDestroy (
|
|||
remove(toRemovePath)
|
||||
.catch(err => logger.error('Cannot remove torrent file %s in webtorrent download.', toRemovePath, { err }))
|
||||
}
|
||||
|
||||
if (err) {
|
||||
logger.warn('Cannot destroy webtorrent in timeout.', { err })
|
||||
}
|
||||
|
||||
return res()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue