Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lockfile

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lockfile - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

22

lockfile.js

@@ -144,5 +144,5 @@ var fs = require('fs')

// 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!

@@ -153,3 +153,3 @@ var opts_ = Object.create(opts, { stale: { value: false }})

}
return cb(er)
return cb(statEr)
}

@@ -205,3 +205,15 @@

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) {

@@ -208,0 +220,0 @@ exports.unlockSync(path)

{
"name": "lockfile",
"version": "0.3.0",
"version": "0.3.1",
"main": "lockfile.js",

@@ -10,3 +10,4 @@ "directories": {

"devDependencies": {
"tap": "~0.2.5"
"tap": "~0.2.5",
"touch": "0"
},

@@ -13,0 +14,0 @@ "scripts": {

@@ -5,2 +5,3 @@ var test = require('tap').test

var fs = require('fs')
var touch = require('touch')

@@ -15,2 +16,3 @@ test('setup', function (t) {

try { lockFile.unlockSync('contentious-lock') } catch (er) {}
try { lockFile.unlockSync('stale-wait-lock') } catch (er) {}
t.end()

@@ -130,3 +132,3 @@ })

var opts = { stale: 1 }
setTimeout(next, 10)
setTimeout(next, 1000)
function next () {

@@ -151,3 +153,3 @@ lockFile.check('stale-lock', opts, function (er, locked) {

lockFile.lockSync('stale-lock')
setTimeout(next, 10)
setTimeout(next, 1000)
function next () {

@@ -263,2 +265,24 @@ var locked

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) {

@@ -272,4 +296,5 @@ try { lockFile.unlockSync('basic-lock') } catch (er) {}

try { lockFile.unlockSync('contentious-lock') } catch (er) {}
try { lockFile.unlockSync('stale-wait-lock') } catch (er) {}
t.end()
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc