Socket
Socket
Sign inDemoInstall

trash

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trash - npm Package Compare versions

Comparing version 6.0.0 to 6.1.0

59

lib/linux.js

@@ -11,24 +11,22 @@ 'use strict';

const moveFile = require('move-file');
const {procfs} = require('@stroncium/procfs');
const pWriteFile = promisify(fs.writeFile);
const lstat = promisify(fs.lstat);
const writeFile = promisify(fs.writeFile);
const trash = async filePath => {
const trashDirectory = await xdgTrashdir(filePath);
// Educated guess, values of 16 to 64 seem to be optimal for modern SSD, 8-16 and 64-128 can be a bit slower.
// We should be ok as long as ssdCount <= cpuCount <= ssdCount*16.
// For slower media this is not as important and we rely on OS handling it for us.
const concurrency = os.cpus().length * 8;
const trash = async (filePath, trashPaths) => {
const name = uuid.v4();
const destination = path.join(trashDirectory, 'files', name);
const trashInfoPath = path.join(trashDirectory, 'info', `${name}.trashinfo`);
const destination = path.join(trashPaths.filesPath, name);
const trashInfoPath = path.join(trashPaths.infoPath, `${name}.trashinfo`);
const trashInfoData = `
[Trash Info]
Path=${filePath.replace(/\s/g, '%20')}
DeletionDate=${(new Date()).toISOString()}
`.trim();
const trashInfoData = `[Trash Info]\nPath=${filePath.replace(/\s/g, '%20')}\nDeletionDate=${(new Date()).toISOString()}`;
await Promise.all([
moveFile(filePath, destination),
(async () => {
// TODO: Use the `fs.mkdir` with `recursive` option when targeting Node.js 12.
await makeDir(path.dirname(trashInfoPath));
await pWriteFile(trashInfoPath, trashInfoData);
})()
writeFile(trashInfoPath, trashInfoData)
]);

@@ -42,2 +40,31 @@

module.exports = async paths => pMap(paths, trash, {concurrency: os.cpus().length});
module.exports = async paths => {
const mountPointMap = new Map(procfs.processMountinfo().map(info => [info.devId, info.mountPoint]));
const trashPathsCache = new Map();
const getDeviceTrashPaths = async devId => {
let trashPathsPromise = trashPathsCache.get(devId);
if (trashPathsPromise === undefined) {
trashPathsPromise = (async () => {
const trashPath = await xdgTrashdir(mountPointMap.get(devId));
const paths = {
filesPath: path.join(trashPath, 'files'),
infoPath: path.join(trashPath, 'info')
};
// TODO: Use the `fs.mkdir` with `recursive` option when targeting Node.js 12.
await makeDir(paths.filesPath);
await makeDir(paths.infoPath);
return paths;
})();
trashPathsCache.set(devId, trashPathsPromise);
}
return trashPathsPromise;
};
return pMap(paths, async filePath => {
const stats = await lstat(filePath);
const trashPaths = await getDeviceTrashPaths(stats.dev);
return trash(filePath, trashPaths);
}, {concurrency});
};
{
"name": "trash",
"version": "6.0.0",
"version": "6.1.0",
"description": "Move files and folders to the trash",

@@ -42,17 +42,18 @@ "license": "MIT",

"dependencies": {
"@stroncium/procfs": "^1.0.0",
"globby": "^7.1.1",
"is-path-inside": "^2.0.0",
"is-path-inside": "^3.0.2",
"make-dir": "^3.0.0",
"move-file": "^1.1.0",
"p-map": "^2.0.0",
"p-map": "^3.0.0",
"p-try": "^2.2.0",
"uuid": "^3.3.2",
"xdg-trashdir": "^2.1.1"
"xdg-trashdir": "^3.1.0"
},
"devDependencies": {
"ava": "^1.4.1",
"ava": "^2.4.0",
"tempfile": "^3.0.0",
"tsd": "^0.7.3",
"xo": "^0.24.0"
"tsd": "^0.11.0",
"xo": "^0.25.3"
}
}
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