Socket
Socket
Sign inDemoInstall

proper-lockfile

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proper-lockfile - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

19

index.js

@@ -16,6 +16,8 @@ 'use strict';

function canonicalPath(file, options, callback) {
if (!options.resolve) {
return callback(null, path.normalize(file));
if (!options.realpath) {
return callback(null, path.resolve(file));
}
// Use realpath to resolve symlinks
// It also resolves relative paths
options.fs.realpath(file, callback);

@@ -32,2 +34,7 @@ }

// If error is not EEXIST than some other error occurred while locking
if (err.code !== 'EEXIST') {
return callback(err);
}
// Otherwise, check if lock is stale by analyzing the file mtime

@@ -147,3 +154,3 @@ if (options.stale <= 0) {

update: null,
resolve: true,
realpath: true,
retries: 0,

@@ -197,4 +204,4 @@ fs: fs

// Not necessary to resolve twice when unlocking
unlock(file, extend({}, options, { resolve: false }), releasedCallback);
// Not necessary to use realpath twice when unlocking
unlock(file, extend({}, options, { realpath: false }), releasedCallback);
});

@@ -214,3 +221,3 @@ });

fs: fs,
resolve: true
realpath: true
}, options);

@@ -217,0 +224,0 @@

{
"name": "proper-lockfile",
"version": "0.5.0",
"version": "0.6.0",
"description": "A inter-process and inter-machine lockfile utility that works on a local or network file system.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -64,3 +64,3 @@ # proper-lockfile [![Build Status](https://travis-ci.org/IndigoUnited/node-proper-lockfile.svg?branch=master)](https://travis-ci.org/IndigoUnited/node-proper-lockfile) [![Coverage Status](https://coveralls.io/repos/IndigoUnited/node-proper-lockfile/badge.png?branch=master)](https://coveralls.io/r/IndigoUnited/node-proper-lockfile?branch=master)

- `retries`: The number of retries or a [retry](https://www.npmjs.org/package/retry) options object, defaults to `0`
- `resolve`: Resolve to a canonical path to handle relative paths & symlinks properly, defaults to `true`
- `realpath`: Resolve symlinks using realpath, defaults to `true` (note that if `true`, the `file` must exist previously)
- `fs`: A custom fs to use, defaults to `graceful-fs`

@@ -102,3 +102,3 @@

- `resolve`: Resolve to a canonical path to handle relative paths & symlinks properly, defaults to `true`
- `realpath`: Resolve symlinks using realpath, defaults to `true` (note that if `true`, the `file` must exist previously)
- `fs`: A custom fs to use, defaults to `graceful-fs`

@@ -105,0 +105,0 @@

@@ -19,3 +19,4 @@ 'use strict';

var tmpFileSymlink = tmpFile + '_symlink';
var tmpFileSymlinkLock = tmpFile + '.lock';
var tmpFileSymlinkLock = tmpFileSymlinkRealPath + '.lock';
var tmpNonExistentFile = path.join(__dirname, 'nonexistentfile');

@@ -25,19 +26,23 @@ function clearLocks(callback) {

if (fs.existsSync(tmpFile)) {
toUnlock.push(function (callback) {
lockfile.unlock(tmpFile, function (err) {
callback(!err || err.code === 'ENOTACQUIRED' ? null : err);
});
toUnlock.push(function (callback) {
lockfile.unlock(tmpFile, { realpath: false }, function (err) {
callback(!err || err.code === 'ENOTACQUIRED' ? null : err);
});
});
toUnlock.push(function (callback) {
lockfile.unlock(tmpFile, { resolve: false }, function (err) {
callback(!err || err.code === 'ENOTACQUIRED' ? null : err);
});
toUnlock.push(function (callback) {
lockfile.unlock(tmpNonExistentFile, { realpath: false }, function (err) {
callback(!err || err.code === 'ENOTACQUIRED' ? null : err);
});
}
});
toUnlock.push(function (callback) {
lockfile.unlock(tmpFileSymlink, { realpath: false }, function (err) {
callback(!err || err.code === 'ENOTACQUIRED' ? null : err);
});
});
if (fs.existsSync(tmpFileSymlink)) {
toUnlock.push(function (callback) {
lockfile.unlock(tmpFileSymlink, { resolve: false }, function (err) {
lockfile.unlock(tmpFileSymlink, function (err) {
callback(!err || err.code === 'ENOTACQUIRED' ? null : err);

@@ -72,4 +77,4 @@ });

it('should fail if the file does not exist', function (next) {
lockfile.lock('filethatwillneverexist', function (err) {
it('should fail if the file does not exist by default', function (next) {
lockfile.lock(tmpNonExistentFile, function (err) {
expect(err).to.be.an(Error);

@@ -82,2 +87,10 @@ expect(err.code).to.be('ENOENT');

it('should not fail if the file does not exist and realpath is false', function (next) {
lockfile.lock(tmpNonExistentFile, { realpath: false }, function (err) {
expect(err).to.not.be.ok();
next();
});
});
it('should create the lockfile', function (next) {

@@ -138,3 +151,3 @@ lockfile.lock(tmpFile, function (err) {

it('should resolve to a canonical path', function (next) {
it('should resolve symlinks by default', function (next) {
// Create a symlink to the tmp file

@@ -150,3 +163,8 @@ fs.symlinkSync(tmpFileRealPath, tmpFileSymlinkRealPath);

next();
lockfile.lock(tmpFile + '/../../test/tmp', function (err) {
expect(err).to.be.an(Error);
expect(err.code).to.be('ELOCKED');
next();
});
});

@@ -156,13 +174,13 @@ });

it('should only normalize the path if resolve is false', function (next) {
it('should not resolve symlinks if realpath is false', function (next) {
// Create a symlink to the tmp file
fs.symlinkSync(tmpFileRealPath, tmpFileSymlinkRealPath);
lockfile.lock(tmpFileSymlink, { resolve: false }, function (err) {
lockfile.lock(tmpFileSymlink, { realpath: false }, function (err) {
expect(err).to.not.be.ok();
lockfile.lock(tmpFile, { resolve: false }, function (err) {
lockfile.lock(tmpFile, { realpath: false }, function (err) {
expect(err).to.not.be.ok();
lockfile.lock(tmpFile + '/../test/tmp', { resolve: false }, function (err) {
lockfile.lock(tmpFile + '/../../test/tmp', { realpath: false }, function (err) {
expect(err).to.be.an(Error);

@@ -758,4 +776,2 @@ expect(err.code).to.be('ELOCKED');

if (err) {
stdout += 'Exit code #' + err.status;
if (process.env.TRAVIS) {

@@ -762,0 +778,0 @@ process.stdout.write(stdout);

Sorry, the diff of this file is not supported yet

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