Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-02-06 04:50:40 +0400
committerisaacs <i@izs.me>2013-02-06 04:50:40 +0400
commit2cc8d398747a803dcc2a3ef5f12467798324a6d4 (patch)
tree506aa53449b8fe17b0896963d6216681bb76436f /node_modules/lockfile
parent87899ec660b5a7560a517cb7b22352cc7c2fc709 (diff)
lockfile@0.3.0
Diffstat (limited to 'node_modules/lockfile')
-rw-r--r--node_modules/lockfile/lockfile.js34
-rw-r--r--node_modules/lockfile/package.json10
-rw-r--r--node_modules/lockfile/test/basic.js2
3 files changed, 9 insertions, 37 deletions
diff --git a/node_modules/lockfile/lockfile.js b/node_modules/lockfile/lockfile.js
index 8404254f8..c5e62f414 100644
--- a/node_modules/lockfile/lockfile.js
+++ b/node_modules/lockfile/lockfile.js
@@ -25,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
}
@@ -170,43 +170,19 @@ function notStale (er, path, opts, cb) {
if (typeof opts.wait !== 'number' || opts.wait <= 0)
return cb(er)
+ // console.error('wait', path, opts.wait)
// wait for some ms for the lock to clear
var start = Date.now()
var end = start + opts.wait
function retry () {
var now = Date.now()
- if (now > end)
- return
-
- // maybe already closed.
- try { watcher.close() } catch (e) {}
- clearTimeout(timer)
var newWait = end - now
- var opts_ = Object.create(opts, { wait: { value: newWait }})
- exports.lock(path, opts_, cb)
- }
-
- 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()
+ var newOpts = Object.create(opts, { wait: { value: newWait }})
+ exports.lock(path, newOpts, cb)
}
- var timer = setTimeout(function () {
- try { watcher.close() } catch (e) {}
- cb(er)
- }, opts.wait)
+ var timer = setTimeout(retry, 10)
}
exports.lockSync = function (path, opts) {
diff --git a/node_modules/lockfile/package.json b/node_modules/lockfile/package.json
index 055a4c0df..6846b944e 100644
--- a/node_modules/lockfile/package.json
+++ b/node_modules/lockfile/package.json
@@ -1,6 +1,6 @@
{
"name": "lockfile",
- "version": "0.2.2",
+ "version": "0.3.0",
"main": "lockfile.js",
"directories": {
"test": "test"
@@ -32,10 +32,6 @@
"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",
"readmeFilename": "README.md",
- "_id": "lockfile@0.2.2",
- "dist": {
- "shasum": "273329ed492f3abe71a910ac89b83adff32c9aab"
- },
- "_from": "lockfile@0.2.2",
- "_resolved": "https://registry.npmjs.org/lockfile/-/lockfile-0.2.2.tgz"
+ "_id": "lockfile@0.3.0",
+ "_from": "lockfile@~0.3.0"
}
diff --git a/node_modules/lockfile/test/basic.js b/node_modules/lockfile/test/basic.js
index 874196308..c4d5ebae7 100644
--- a/node_modules/lockfile/test/basic.js
+++ b/node_modules/lockfile/test/basic.js
@@ -23,7 +23,7 @@ test('lock contention', function (t) {
// 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 = 20
+ var overhead = 200
var wait = N * overhead + delay
// first make it locked, so that everyone has to wait