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-04-29 19:52:07 +0400
committerisaacs <i@izs.me>2013-04-29 19:58:36 +0400
commit8bcdee7a22f95fc27918abae0eb87c5f5ad926db (patch)
tree73f380dc46b1f1df952164d85676571ed49c867e /node_modules/lockfile
parent57162e9df90f6b6fa3f019b0cf3630811c83e808 (diff)
lockfile@0.3.1
Diffstat (limited to 'node_modules/lockfile')
-rw-r--r--node_modules/lockfile/lockfile.js22
-rw-r--r--node_modules/lockfile/package.json16
-rw-r--r--node_modules/lockfile/test/basic.js29
3 files changed, 56 insertions, 11 deletions
diff --git a/node_modules/lockfile/lockfile.js b/node_modules/lockfile/lockfile.js
index c5e62f414..462127960 100644
--- a/node_modules/lockfile/lockfile.js
+++ b/node_modules/lockfile/lockfile.js
@@ -141,15 +141,15 @@ exports.lock = function (path, opts, cb) {
if (er.code !== 'EEXIST') return cb(er)
// someone's got this one. see if it's valid.
- if (opts.stale) fs.stat(path, function (er, st) {
- if (er) {
- if (er.code === 'ENOENT') {
+ if (opts.stale) fs.stat(path, function (statEr, st) {
+ if (statEr) {
+ if (statEr.code === 'ENOENT') {
// expired already!
var opts_ = Object.create(opts, { stale: { value: false }})
exports.lock(path, opts_, cb)
return
}
- return cb(er)
+ return cb(statEr)
}
var age = Date.now() - st.ctime.getTime()
@@ -200,7 +200,19 @@ exports.lockSync = function (path, opts) {
if (opts.stale) {
var st = fs.statSync(path)
- var age = Date.now() - st.ctime.getTime()
+ var ct = st.ctime.getTime()
+ if (!(ct % 1000) && (opts.stale % 1000)) {
+ // probably don't have subsecond resolution.
+ // round up the staleness indicator.
+ // Yes, this will be wrong 1/1000 times on platforms
+ // with subsecond stat precision, but that's acceptable
+ // in exchange for not mistakenly removing locks on
+ // most other systems.
+ console.error('1bump up stale', opts.stale)
+ opts.stale = 1000 * Math.ceil(opts.stale / 1000)
+ console.error('2bump up stale', opts.stale)
+ }
+ var age = Date.now() - ct
if (age > opts.stale) {
exports.unlockSync(path)
return exports.lockSync(path, opts)
diff --git a/node_modules/lockfile/package.json b/node_modules/lockfile/package.json
index 6846b944e..77b6da211 100644
--- a/node_modules/lockfile/package.json
+++ b/node_modules/lockfile/package.json
@@ -1,13 +1,14 @@
{
"name": "lockfile",
- "version": "0.3.0",
+ "version": "0.3.1",
"main": "lockfile.js",
"directories": {
"test": "test"
},
"dependencies": {},
"devDependencies": {
- "tap": "~0.2.5"
+ "tap": "~0.2.5",
+ "touch": "0"
},
"scripts": {
"test": "tap test/*.js"
@@ -32,6 +33,13 @@
"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.3.0",
- "_from": "lockfile@~0.3.0"
+ "bugs": {
+ "url": "https://github.com/isaacs/lockfile/issues"
+ },
+ "_id": "lockfile@0.3.1",
+ "dist": {
+ "shasum": "8b1772b4a9f16d964db05951ce6697825ed248e8"
+ },
+ "_from": "lockfile@0.3.1",
+ "_resolved": "https://registry.npmjs.org/lockfile/-/lockfile-0.3.1.tgz"
}
diff --git a/node_modules/lockfile/test/basic.js b/node_modules/lockfile/test/basic.js
index c4d5ebae7..41dbcdc32 100644
--- a/node_modules/lockfile/test/basic.js
+++ b/node_modules/lockfile/test/basic.js
@@ -2,6 +2,7 @@ var test = require('tap').test
var lockFile = require('../lockfile.js')
var path = require('path')
var fs = require('fs')
+var touch = require('touch')
test('setup', function (t) {
try { lockFile.unlockSync('basic-lock') } catch (er) {}
@@ -11,6 +12,7 @@ test('setup', function (t) {
try { lockFile.unlockSync('watch-lock') } catch (er) {}
try { lockFile.unlockSync('retry-lock') } catch (er) {}
try { lockFile.unlockSync('contentious-lock') } catch (er) {}
+ try { lockFile.unlockSync('stale-wait-lock') } catch (er) {}
t.end()
})
@@ -125,7 +127,7 @@ test('staleness test', function (t) {
if (er) throw er
var opts = { stale: 1 }
- setTimeout(next, 10)
+ setTimeout(next, 1000)
function next () {
lockFile.check('stale-lock', opts, function (er, locked) {
if (er) throw er
@@ -145,7 +147,7 @@ test('staleness test', function (t) {
test('staleness sync test', function (t) {
var opts = { stale: 1 }
lockFile.lockSync('stale-lock')
- setTimeout(next, 10)
+ setTimeout(next, 1000)
function next () {
var locked
locked = lockFile.checkSync('stale-lock', opts)
@@ -256,6 +258,28 @@ test('retry sync', function (t) {
t.end()
})
+test('wait and stale together', function (t) {
+ // first locker.
+ var interval
+ lockFile.lock('stale-wait-lock', function(er) {
+ // keep refreshing the lock, so we keep it forever
+ interval = setInterval(function() {
+ touch.sync('stale-wait-lock')
+ }, 10)
+
+ // try to get another lock. this must fail!
+ var opt = { stale: 1000, wait: 2000 }
+ lockFile.lock('stale-wait-lock', opt, function (er) {
+ if (!er)
+ t.fail('got second lock? that unpossible!')
+ else
+ t.pass('second lock failed, as i have foreseen it')
+ clearInterval(interval)
+ t.end()
+ })
+ })
+})
+
test('cleanup', function (t) {
try { lockFile.unlockSync('basic-lock') } catch (er) {}
try { lockFile.unlockSync('sync-lock') } catch (er) {}
@@ -264,6 +288,7 @@ test('cleanup', function (t) {
try { lockFile.unlockSync('watch-lock') } catch (er) {}
try { lockFile.unlockSync('retry-lock') } catch (er) {}
try { lockFile.unlockSync('contentious-lock') } catch (er) {}
+ try { lockFile.unlockSync('stale-wait-lock') } catch (er) {}
t.end()
})