Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local file deletion on `torrent.destroy` #1102

Open
wants to merge 4 commits into
base: master
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Add local file deletion on `torrent.destroy`

When we call `torrent.destroy` and we are not running in a browser, we use
`rimraf` to delete the folder containing the torrent files.
  • Loading branch information
Rowern committed Apr 13, 2017
commit e06b121e1697d9be628af2184655587c064df5db
@@ -25,6 +25,7 @@ var path = require('path')
var Piece = require('torrent-piece')
var pump = require('pump')
var randomIterate = require('random-iterate')
var rimraf = require('rimraf')
var sha1 = require('simple-sha1')
var speedometer = require('speedometer')
var uniq = require('uniq')
@@ -71,7 +72,7 @@ function Torrent (torrentId, client, opts) {

this.announce = opts.announce
this.urlList = opts.urlList

this._fromLocalFile = opts.path
this.path = opts.path
this._store = opts.store || FSChunkStore
this._getAnnounceOpts = opts.getAnnounceOpts
@@ -686,6 +687,14 @@ Torrent.prototype._destroy = function (err, cb) {
})
}

// We won't delete torrent created from local file
// We also can't delete file created on a browser
if (typeof window === 'undefined' && !self._fromLocalFile && self.path) {
tasks.push(function (cb) {
rimraf(self.path, cb)
})
}

parallel(tasks, cb)

if (err) {
@@ -49,6 +49,7 @@
"range-parser": "^1.2.0",
"readable-stream": "^2.1.4",
"render-media": "^2.8.0",
"rimraf": "^2.6.1",
"run-parallel": "^1.1.6",
"run-parallel-limit": "^1.0.3",
"safe-buffer": "^5.0.1",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.