Socket
Socket
Sign inDemoInstall

fs-jetpack

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-jetpack - npm Package Compare versions

Comparing version 2.2.1 to 2.2.2

3

CHANGELOG.md

@@ -0,1 +1,4 @@

# 2.2.2 (2019-02-19)
- Use rimraf as internal implementation of `remove()` to fix https://github.com/szwacz/fs-jetpack/issues/80
# 2.2.1 (2019-01-20)

@@ -2,0 +5,0 @@ - `find()` no longer crashes on ENOENT (e.g. when one of the files has been deleted by other process).

98

lib/remove.js
"use strict";
const pathUtil = require("path");
const fs = require("./utils/fs");
const rimraf = require('rimraf');
const promisify = require('./utils/promisify');
const promisifiedRimraf = promisify(rimraf);
const validate = require("./utils/validate");
const list = require("./list");

@@ -18,25 +18,3 @@ const validateInput = (methodName, path) => {

const removeSync = path => {
try {
// Assume the path is a file and just try to remove it.
fs.unlinkSync(path);
} catch (err) {
if (
err.code === "EPERM" ||
err.code === "EISDIR" ||
err.code === "ENOTEMPTY"
) {
// Must delete everything inside the directory first.
list.sync(path).forEach(filename => {
removeSync(pathUtil.join(path, filename));
});
// Everything inside directory has been removed,
// it's safe now do go for the directory itself.
fs.rmdirSync(path);
} else if (err.code === "ENOENT") {
// File already doesn't exist. We're done.
} else {
// Something unexpected happened. Rethrow original error.
throw err;
}
}
rimraf.sync(path, { disableGlob: true });
};

@@ -48,70 +26,4 @@

const removeAsyncInternal = (path, retryCount) => {
return new Promise((resolve, reject) => {
const retryInAWhileOrFail = err => {
if (retryCount === 3) {
// Too many retries already. Fail.
reject(err);
} else {
// Try the same action after some pause.
setTimeout(() => {
removeAsyncInternal(path, retryCount + 1).then(resolve, reject);
}, 100);
}
};
const removeEverythingInsideDirectory = () => {
return list.async(path).then(filenamesInsideDir => {
const promises = filenamesInsideDir.map(filename => {
return removeAsyncInternal(pathUtil.join(path, filename), 0);
});
return Promise.all(promises);
});
};
// Assume the path is a file and just try to remove it.
fs.unlink(path)
.then(resolve)
.catch(err => {
if (err.code === "EBUSY") {
retryInAWhileOrFail(err);
} else if (
err.code === "EPERM" ||
err.code === "EISDIR" ||
err.code === "ENOTEMPTY"
) {
// File deletion attempt failed. Probably it's not a file, it's a directory.
// So try to proceed with that assumption.
removeEverythingInsideDirectory()
.then(() => {
// Now go for the directory.
return fs.rmdir(path);
})
.then(resolve)
.catch(err2 => {
if (
err2.code === "EBUSY" ||
err2.code === "EPERM" ||
err2.code === "ENOTEMPTY"
) {
// Failed again. This might be due to other processes reading
// something inside the directory. Let's take a nap and retry.
retryInAWhileOrFail(err2);
} else {
reject(err2);
}
});
} else if (err.code === "ENOENT") {
// File already doesn't exist. We're done.
resolve();
} else {
// Something unexpected happened. Rethrow original error.
reject(err);
}
});
});
};
const removeAsync = path => {
return removeAsyncInternal(path, 0);
return promisifiedRimraf(path, { disableGlob: true });
};

@@ -118,0 +30,0 @@

{
"name": "fs-jetpack",
"description": "Better file system API",
"version": "2.2.1",
"version": "2.2.2",
"author": "Jakub Szwacz <jakub@szwacz.com>",
"dependencies": {
"minimatch": "^3.0.2"
"minimatch": "^3.0.2",
"rimraf": "^2.6.3"
},

@@ -9,0 +10,0 @@ "devDependencies": {

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