diff options
author | isaacs <i@izs.me> | 2013-09-07 23:21:47 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-09-07 23:21:47 +0400 |
commit | 3e1cb862f9a7e279ca5aeb60bbdfae9f70e9cfbc (patch) | |
tree | f829c90e0edb1a02f927c1f492897c9726f03091 /node_modules/lockfile | |
parent | e703217e28869b49b25e9f8524084becc65de468 (diff) |
lockfile@0.4.2
Diffstat (limited to 'node_modules/lockfile')
-rw-r--r-- | node_modules/lockfile/lockfile.js | 16 | ||||
-rw-r--r-- | node_modules/lockfile/package.json | 10 | ||||
-rw-r--r-- | node_modules/lockfile/test/basic.js | 26 |
3 files changed, 44 insertions, 8 deletions
diff --git a/node_modules/lockfile/lockfile.js b/node_modules/lockfile/lockfile.js index 1eecd5f79..b82f1f0d6 100644 --- a/node_modules/lockfile/lockfile.js +++ b/node_modules/lockfile/lockfile.js @@ -6,6 +6,12 @@ if (process.version.match(/^v0\.[0-6]/)) { wx = c.O_TRUNC | c.O_CREAT | c.O_WRONLY | c.O_EXCL } +var os = require('os') +var filetime = 'ctime' +if (os.platform() == "win32") { + filetime = 'mtime' +} + var debug var util = require('util') if (util.debuglog) @@ -32,7 +38,7 @@ process.on('exit', function () { // XXX https://github.com/joyent/node/issues/3555 // Remove when node 0.8 is deprecated. -if (/^v0\.[0-8]/.test(process.version)) { +if (/^v0\.[0-8]\./.test(process.version)) { debug('uncaughtException, version = %s', process.version) process.on('uncaughtException', function H (er) { debug('uncaughtException') @@ -86,7 +92,7 @@ exports.check = function (path, opts, cb) { }) fs.close(fd, function (er) { - var age = Date.now() - st.ctime.getTime() + var age = Date.now() - st[filetime].getTime() return cb(er, age <= opts.stale) }) }) @@ -119,7 +125,7 @@ exports.checkSync = function (path, opts) { } finally { fs.closeSync(fd) } - var age = Date.now() - st.ctime.getTime() + var age = Date.now() - st[filetime].getTime() return (age <= opts.stale) } } @@ -173,7 +179,7 @@ exports.lock = function (path, opts, cb) { return cb(statEr) } - var age = Date.now() - st.ctime.getTime() + var age = Date.now() - st[filetime].getTime() if (age > opts.stale) { debug('lock stale', path, opts_) exports.unlock(path, function (er) { @@ -230,7 +236,7 @@ exports.lockSync = function (path, opts) { if (opts.stale) { var st = fs.statSync(path) - var ct = st.ctime.getTime() + var ct = st[filetime].getTime() if (!(ct % 1000) && (opts.stale % 1000)) { // probably don't have subsecond resolution. // round up the staleness indicator. diff --git a/node_modules/lockfile/package.json b/node_modules/lockfile/package.json index ea1f5a919..39d9a857c 100644 --- a/node_modules/lockfile/package.json +++ b/node_modules/lockfile/package.json @@ -1,6 +1,6 @@ { "name": "lockfile", - "version": "0.4.0", + "version": "0.4.2", "main": "lockfile.js", "directories": { "test": "test" @@ -36,6 +36,10 @@ "bugs": { "url": "https://github.com/isaacs/lockfile/issues" }, - "_id": "lockfile@0.4.0", - "_from": "lockfile@latest" + "_id": "lockfile@0.4.2", + "dist": { + "shasum": "ab91f5d3745bc005ae4fa34d078910d1f2b9612d" + }, + "_from": "lockfile@0.4.2", + "_resolved": "https://registry.npmjs.org/lockfile/-/lockfile-0.4.2.tgz" } diff --git a/node_modules/lockfile/test/basic.js b/node_modules/lockfile/test/basic.js index fb01de3f4..23e824879 100644 --- a/node_modules/lockfile/test/basic.js +++ b/node_modules/lockfile/test/basic.js @@ -13,6 +13,7 @@ test('setup', function (t) { try { lockFile.unlockSync('retry-lock') } catch (er) {} try { lockFile.unlockSync('contentious-lock') } catch (er) {} try { lockFile.unlockSync('stale-wait-lock') } catch (er) {} + try { lockFile.unlockSync('stale-windows-lock') } catch (er) {} t.end() }) @@ -249,6 +250,30 @@ test('wait and stale together', function (t) { }) }) + +test('stale windows file tunneling test', function (t) { + // for windows only + // nt file system tunneling feature will make file creation time not updated + var opts = { stale: 1000 } + lockFile.lockSync('stale-windows-lock') + setTimeout(next, 2000) + function next () { + var locked + lockFile.unlockSync('stale-windows-lock') + lockFile.lockSync('stale-windows-lock', opts) + locked = lockFile.checkSync('stale-windows-lock', opts) + t.ok(locked, "should be locked and not stale") + lockFile.lock('stale-windows-lock', opts, function (er) { + if (!er) + t.fail('got second lock? impossible, windows file tunneling problem!') + else + t.pass('second lock failed, windows file tunneling problem fixed') + t.end() + }) + } +}) + + test('cleanup', function (t) { try { lockFile.unlockSync('basic-lock') } catch (er) {} try { lockFile.unlockSync('sync-lock') } catch (er) {} @@ -258,6 +283,7 @@ test('cleanup', function (t) { try { lockFile.unlockSync('retry-lock') } catch (er) {} try { lockFile.unlockSync('contentious-lock') } catch (er) {} try { lockFile.unlockSync('stale-wait-lock') } catch (er) {} + try { lockFile.unlockSync('stale-windows-lock') } catch (er) {} t.end() }) |