diff --git a/package.json b/package.json index cdcefbe2..8b61d773 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "compression": "^1.6.1", "cookie-parser": "^1.4.3", "debug": "^2.2.0", - "del": "^2.2.1", "events": "^1.1.0", "express": "^4.14.0", "feedsub": "^0.3.0", @@ -35,6 +34,7 @@ "passport-jwt": "^2.1.0", "pug": "^2.0.0-beta3", "q": "^1.4.1", + "rimraf": "^2.6.1", "serve-favicon": "^2.3.0", "xmlrpc": "^1.3.0" }, diff --git a/server/models/client.js b/server/models/client.js index 16e903c1..546c87c2 100644 --- a/server/models/client.js +++ b/server/models/client.js @@ -1,9 +1,9 @@ 'use strict'; const archiver = require('archiver'); -const del = require('del'); const fs = require('fs'); const path = require('path'); +const rimraf = require('rimraf'); const util = require('util'); const clientResponseUtil = require('../util/clientResponseUtil'); @@ -90,26 +90,29 @@ var client = { let filesToDelete = null; let eraseTorrentsRequest = new ClientRequest(); - if (options.deleteData) { - const torrents = torrentCollection.torrents; - - filesToDelete = options.hashes.reduce((accumulator, hash) => { - const torrent = torrents[hash]; - - if (torrent.isMultiFile && torrent.directory != null) { - accumulator.push(torrent.directory); - } else if (torrent.directory != null && torrent.name != null) { - accumulator.push(path.join(torrent.directory, torrent.name)); - } - - return accumulator; - }, []); - } - eraseTorrentsRequest.removeTorrents({hashes: options.hashes}); eraseTorrentsRequest.onComplete((response, error) => { - if (options.deleteData && filesToDelete.length > 0) { - del(filesToDelete, {force: true}); + if (options.deleteData) { + const torrents = torrentCollection.torrents; + + options.hashes.forEach(hash => { + let fileToDelete = null; + const torrent = torrents[hash]; + + if (torrent.isMultiFile && torrent.directory != null) { + fileToDelete = torrent.directory; + } else if (torrent.directory != null && torrent.name != null) { + fileToDelete = path.join(torrent.directory, torrent.name); + } + + if (fileToDelete != null) { + rimraf(fileToDelete, {disableGlob: true}, error => { + if (error) { + console.error(`Error deleting file: ${fileToDelete}\n${error}`); + } + }); + } + }); } client.updateTorrentList();