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

rwlockfile

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rwlockfile - npm Package Compare versions

Comparing version 1.3.5 to 1.3.6

11

package.json
{
"name": "rwlockfile",
"description": "lockfile utility with reader/writers",
"version": "1.3.5",
"version": "1.3.6",
"author": "Jeff Dickey @dickeyxxx",
"bugs": "https://github.com/dickeyxxx/rwlockfile/issues",
"dependencies": {
"graceful-fs": ">= 4.0.0",
"ps-node": "0.1.4"
"graceful-fs": "^4.0.0",
"ps-node": "^0.1.4",
"rimraf": "^2.6.1"
},

@@ -14,7 +15,7 @@ "devDependencies": {

"chai-as-promised": "6.0.0",
"jsdoc-to-markdown": "2.0.1",
"jsdoc-to-markdown": "3.0.0",
"mocha": "3.2.0",
"np": "2.12.0",
"nyc": "10.1.2",
"standard": "8.6.0"
"standard": "9.0.1"
},

@@ -21,0 +22,0 @@ "homepage": "https://github.com/dickeyxxx/rwlockfile",

@@ -6,2 +6,4 @@ /**

const fs = require('graceful-fs')
const path = require('path')
const rimraf = require('rimraf')

@@ -31,3 +33,3 @@ let locks = {}

function unlock (path) {
return new Promise(resolve => fs.unlink(path, resolve))
return new Promise(resolve => rimraf(path, resolve))
}

@@ -41,3 +43,3 @@

try {
fs.unlinkSync(path)
rimraf.sync(path)
} catch (err) { }

@@ -47,15 +49,16 @@ delete locks[path]

function lock (path, timeout) {
function lock (p, timeout) {
let pidPath = path.join(p, 'pid')
return new Promise((resolve, reject) => {
fs.open(path, 'wx', (err, fd) => {
fs.mkdir(p, (err) => {
if (!err) {
locks[path] = fd
fs.write(fd, process.pid.toString(), resolve)
locks[p] = 1
fs.writeFile(pidPath, process.pid.toString(), resolve)
return
}
if (err.code !== 'EEXIST') return reject(err)
lockActive(path).then(active => {
if (!active) return unlock(path).then(resolve).catch(reject)
if (timeout <= 0) throw new Error(`${path} is locked`)
wait().then(() => lock(path, timeout - 100).then(resolve).catch(reject))
lockActive(pidPath).then(active => {
if (!active) return unlock(p).then(resolve).catch(reject)
if (timeout <= 0) throw new Error(`${p} is locked`)
wait().then(() => lock(p, timeout - 100).then(resolve).catch(reject))
}).catch(reject)

@@ -85,3 +88,3 @@ })

function getReaders (path) {
return readFile(path + '.readers')
return readFile(path + '.readers', 'utf8')
.then(f => f.split('\n').map(r => parseInt(r)))

@@ -194,4 +197,4 @@ .catch(() => [])

*/
function hasWriter (path) {
return Promise.resolve(readFile(path + '.writer').catch(err => {
function hasWriter (p) {
return Promise.resolve(readFile(path.join(p + '.writer', 'pid')).catch(err => {
if (err.code !== 'ENOENT') throw err

@@ -198,0 +201,0 @@ }))

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