rwlockfile
Advanced tools
Comparing version 1.3.5 to 1.3.6
{ | ||
"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 @@ })) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8740
186
3
+ Addedrimraf@^2.6.1
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedps-node@0.1.6(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedps-node@0.1.4(transitive)
Updatedgraceful-fs@^4.0.0
Updatedps-node@^0.1.4