summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/lockfile
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-02-06 08:39:27 -0800
committerisaacs <i@izs.me>2013-02-06 08:39:31 -0800
commit5aef65a98a9427bcd6f41d8f65235bd26883d2d7 (patch)
treef1e290db817cedc3af49d6f6423ca7033cbdee18 /deps/npm/node_modules/lockfile
parenta86ebbe2885fe6f2b6adeeaa95c8abc12d821d7b (diff)
downloadandroid-node-v8-5aef65a98a9427bcd6f41d8f65235bd26883d2d7.tar.gz
android-node-v8-5aef65a98a9427bcd6f41d8f65235bd26883d2d7.tar.bz2
android-node-v8-5aef65a98a9427bcd6f41d8f65235bd26883d2d7.zip
npm: Upgrade to v1.2.10
Diffstat (limited to 'deps/npm/node_modules/lockfile')
-rw-r--r--deps/npm/node_modules/lockfile/LICENSE22
-rw-r--r--deps/npm/node_modules/lockfile/lockfile.js78
-rw-r--r--deps/npm/node_modules/lockfile/package.json7
-rw-r--r--deps/npm/node_modules/lockfile/test/basic.js43
4 files changed, 89 insertions, 61 deletions
diff --git a/deps/npm/node_modules/lockfile/LICENSE b/deps/npm/node_modules/lockfile/LICENSE
index 74489e2e26..0c44ae716d 100644
--- a/deps/npm/node_modules/lockfile/LICENSE
+++ b/deps/npm/node_modules/lockfile/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) Isaac Z. Schlueter
+Copyright (c) Isaac Z. Schlueter ("Author")
All rights reserved.
The BSD License
@@ -6,20 +6,22 @@ The BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
+
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
+
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
-THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/deps/npm/node_modules/lockfile/lockfile.js b/deps/npm/node_modules/lockfile/lockfile.js
index 0bc54169c5..c5e62f4142 100644
--- a/deps/npm/node_modules/lockfile/lockfile.js
+++ b/deps/npm/node_modules/lockfile/lockfile.js
@@ -8,6 +8,10 @@ if (process.version.match(/^v0.[456]/)) {
var locks = {}
+function hasOwnProperty (obj, prop) {
+ return Object.prototype.hasOwnProperty.call(obj, prop)
+}
+
process.on('exit', function () {
// cleanup
Object.keys(locks).forEach(exports.unlockSync)
@@ -21,7 +25,7 @@ process.on('uncaughtException', function H (er) {
})
if (!l.length) {
// cleanup
- Object.keys(locks).forEach(exports.unlockSync)
+ try { Object.keys(locks).forEach(exports.unlockSync) } catch (e) {}
process.removeListener('uncaughtException', H)
throw er
}
@@ -29,20 +33,21 @@ process.on('uncaughtException', function H (er) {
exports.unlock = function (path, cb) {
// best-effort. unlocking an already-unlocked lock is a noop
- fs.unlink(path, function (unlinkEr) {
- if (!locks.hasOwnProperty(path)) return cb()
- fs.close(locks[path], function (closeEr) {
- delete locks[path]
- cb()
- })
- })
+ if (hasOwnProperty(locks, path))
+ fs.close(locks[path], unlink)
+ else
+ unlink()
+
+ function unlink () {
+ delete locks[path]
+ fs.unlink(path, function (unlinkEr) { cb() })
+ }
}
exports.unlockSync = function (path) {
- try { fs.unlinkSync(path) } catch (er) {}
- if (!locks.hasOwnProperty(path)) return
// best-effort. unlocking an already-unlocked lock is a noop
- try { fs.close(locks[path]) } catch (er) {}
+ try { fs.closeSync(locks[path]) } catch (er) {}
+ try { fs.unlinkSync(path) } catch (er) {}
delete locks[path]
}
@@ -161,46 +166,23 @@ exports.lock = function (path, opts, cb) {
}
function notStale (er, path, opts, cb) {
- if (typeof opts.wait === 'number' && opts.wait > 0) {
- // wait for some ms for the lock to clear
- var start = Date.now()
-
- var retried = false
- function retry () {
- if (retried) return
- retried = true
- // maybe already closed.
- try { watcher.close() } catch (e) {}
- clearTimeout(timer)
- var newWait = Date.now() - start
- var opts_ = Object.create(opts, { wait: { value: newWait }})
- exports.lock(path, opts_, cb)
- }
+ // if we can't wait, then just call it a failure
+ if (typeof opts.wait !== 'number' || opts.wait <= 0)
+ return cb(er)
- try {
- var watcher = fs.watch(path, function (change) {
- if (change === 'rename') {
- // ok, try and get it now.
- // if this fails, then continue waiting, maybe.
- retry()
- }
- })
- watcher.on('error', function (er) {
- // usually means it expired before the watcher spotted it
- retry()
- })
- } catch (er) {
- retry()
- }
+ // console.error('wait', path, opts.wait)
+ // wait for some ms for the lock to clear
+ var start = Date.now()
+ var end = start + opts.wait
- var timer = setTimeout(function () {
- try { watcher.close() } catch (e) {}
- cb(er)
- }, opts.wait)
- } else {
- // failed to lock!
- return cb(er)
+ function retry () {
+ var now = Date.now()
+ var newWait = end - now
+ var newOpts = Object.create(opts, { wait: { value: newWait }})
+ exports.lock(path, newOpts, cb)
}
+
+ var timer = setTimeout(retry, 10)
}
exports.lockSync = function (path, opts) {
diff --git a/deps/npm/node_modules/lockfile/package.json b/deps/npm/node_modules/lockfile/package.json
index b93404bcde..6846b944e1 100644
--- a/deps/npm/node_modules/lockfile/package.json
+++ b/deps/npm/node_modules/lockfile/package.json
@@ -1,6 +1,6 @@
{
"name": "lockfile",
- "version": "0.2.1",
+ "version": "0.3.0",
"main": "lockfile.js",
"directories": {
"test": "test"
@@ -31,6 +31,7 @@
"license": "BSD",
"description": "A very polite lock file utility, which endeavors to not litter, and to wait patiently for others.",
"readme": "# lockfile\n\nA very polite lock file utility, which endeavors to not litter, and to\nwait patiently for others.\n\n## Usage\n\n```javascript\nvar lockFile = require('lockfile')\n\n// opts is optional, and defaults to {}\nlockFile.lock('some-file.lock', opts, function (er, fd) {\n // if the er happens, then it failed to acquire a lock.\n // if there was not an error, then the fd is opened in\n // wx mode. If you want to write something to it, go ahead.\n\n // do my stuff, free of interruptions\n // then, some time later, do:\n lockFile.unlock('some-file.lock', function (er) {\n // er means that an error happened, and is probably bad.\n })\n})\n```\n\n## Methods\n\nSync methods return the value/throw the error, others don't. Standard\nnode fs stuff.\n\nAll known locks are removed when the process exits. Of course, it's\npossible for certain types of failures to cause this to fail, but a best\neffort is made to not be a litterbug.\n\n### lockFile.lock(path, [opts], cb)\n\nAcquire a file lock on the specified path. Returns the FD.\n\n### lockFile.lockSync(path, [opts])\n\nAcquire a file lock on the specified path\n\n### lockFile.unlock(path, cb)\n\nClose and unlink the lockfile.\n\n### lockFile.unlockSync(path)\n\nClose and unlink the lockfile.\n\n### lockFile.check(path, [opts], cb)\n\nCheck if the lockfile is locked and not stale.\n\nReturns boolean.\n\n### lockFile.checkSync(path, [opts], cb)\n\nCheck if the lockfile is locked and not stale.\n\nCallback is called with `cb(error, isLocked)`.\n\n## Options\n\n### opts.wait\n\nA number of milliseconds to wait for locks to expire before giving up.\nOnly used by lockFile.lock. Relies on fs.watch. If the lock is not\ncleared by the time the wait expires, then it returns with the original\nerror.\n\n### opts.stale\n\nA number of milliseconds before locks are considered to have expired.\n\n### opts.retries\n\nUsed by lock and lockSync. Retry `n` number of times before giving up.\n\n### opts.retryWait\n\nUsed by lock. Wait `n` milliseconds before retrying.\n",
- "_id": "lockfile@0.2.1",
- "_from": "lockfile@>=0.2"
+ "readmeFilename": "README.md",
+ "_id": "lockfile@0.3.0",
+ "_from": "lockfile@~0.3.0"
}
diff --git a/deps/npm/node_modules/lockfile/test/basic.js b/deps/npm/node_modules/lockfile/test/basic.js
index 77308cdc94..c4d5ebae79 100644
--- a/deps/npm/node_modules/lockfile/test/basic.js
+++ b/deps/npm/node_modules/lockfile/test/basic.js
@@ -10,9 +10,51 @@ test('setup', function (t) {
try { lockFile.unlockSync('stale-lock') } catch (er) {}
try { lockFile.unlockSync('watch-lock') } catch (er) {}
try { lockFile.unlockSync('retry-lock') } catch (er) {}
+ try { lockFile.unlockSync('contentious-lock') } catch (er) {}
t.end()
})
+test('lock contention', function (t) {
+ var gotlocks = 0;
+ var N = 200
+ var delay = 10
+ // allow for some time for each lock acquisition and release.
+ // note that raising N higher will mean that the overhead
+ // increases, because we're creating more and more watchers.
+ // irl, you should never have several hundred contenders for a
+ // single lock, so this situation is somewhat pathological.
+ var overhead = 200
+ var wait = N * overhead + delay
+
+ // first make it locked, so that everyone has to wait
+ lockFile.lock('contentious-lock', function(er, lock) {
+ t.ifError(er, 'acquiring starter')
+ if (er) throw er;
+ t.pass('acquired starter lock')
+ setTimeout(function() {
+ lockFile.unlock('contentious-lock', function (er) {
+ t.ifError(er, 'unlocking starter')
+ if (er) throw er
+ t.pass('unlocked starter')
+ })
+ }, delay)
+ })
+
+ for (var i=0; i < N; i++)
+ lockFile.lock('contentious-lock', { wait: wait }, function(er, lock) {
+ if (er) throw er;
+ lockFile.unlock('contentious-lock', function(er) {
+ if (er) throw er
+ gotlocks++
+ t.pass('locked and unlocked #' + gotlocks)
+ if (gotlocks === N) {
+ t.pass('got all locks')
+ t.end()
+ }
+ })
+ })
+})
+
test('basic test', function (t) {
lockFile.check('basic-lock', function (er, locked) {
if (er) throw er
@@ -221,6 +263,7 @@ test('cleanup', function (t) {
try { lockFile.unlockSync('stale-lock') } catch (er) {}
try { lockFile.unlockSync('watch-lock') } catch (er) {}
try { lockFile.unlockSync('retry-lock') } catch (er) {}
+ try { lockFile.unlockSync('contentious-lock') } catch (er) {}
t.end()
})