Skip to content

Commit

Permalink
fs-storage: rm thunky
Browse files Browse the repository at this point in the history
OS IO cache is way smarter than this stupid indefinite caching.
  • Loading branch information
astro committed Jan 21, 2015
1 parent 4d74b51 commit 5a70596
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/fs-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var path = require('path')
var raf = require('random-access-file')
var rimraf = require('rimraf')
var Storage = require('./storage')
var thunky = require('thunky')

var TMP = fs.existsSync('/tmp') ? '/tmp' : os.tmpDir()
function noop () {}
Expand Down Expand Up @@ -47,7 +46,7 @@ function FSStorage (parsedTorrent, opts) {
var pieceLength = file.pieceLength
var filePath = path.join(self.path, file.path)

var openWrite = thunky(function (cb) {
var openWrite = function (cb) {
var fileDir = path.dirname(filePath)

mkdirp(fileDir, function (err) {
Expand All @@ -58,16 +57,16 @@ function FSStorage (parsedTorrent, opts) {
file.fd = fd
cb(null, fd)
})
})
}

var openRead = thunky(function (cb) {
var openRead = function (cb) {
// TODO: no need for fs.exists call, just try opening and handle error.
// fs.exists then open creates opportunity for race condition.
fs.exists(filePath, function (exists) {
if (exists) return openWrite(cb)
cb(self.nonExistentError)
})
})
}

file.pieces.forEach(function (piece) {
var index = piece.index
Expand Down Expand Up @@ -160,6 +159,7 @@ FSStorage.prototype._onPieceDone = function (piece) {
var writeToNextFile = function (err) {
if (err) return self.emit('error', err)
if (i >= end) {
delete piece.buffer
return cb()
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"simple-get": "^1.0.0",
"simple-sha1": "^2.0.0",
"speedometer": "^0.1.2",
"thunky": "^0.1.0",
"torrent-discovery": "^2.0.1",
"ut_metadata": "^2.1.0",
"ut_pex": "^1.0.1",
Expand Down

0 comments on commit 5a70596

Please sign in to comment.