Comparing version 6.0.0 to 6.1.0
@@ -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" | ||
} | ||
} |
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
53457
158
9
+ Added@stroncium/procfs@^1.0.0
+ Added@sindresorhus/df@3.1.1(transitive)
+ Added@stroncium/procfs@1.2.1(transitive)
+ Addedaggregate-error@3.1.0(transitive)
+ Addedclean-stack@2.2.0(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexeca@2.1.0(transitive)
+ Addedget-stream@5.2.0(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedis-path-inside@3.0.3(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednpm-run-path@3.1.0(transitive)
+ Addedonetime@5.1.2(transitive)
+ Addedp-finally@2.0.1(transitive)
+ Addedp-map@3.0.0(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstrip-final-newline@2.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedxdg-basedir@4.0.0(transitive)
+ Addedxdg-trashdir@3.1.0(transitive)
- Removed@sindresorhus/df@2.1.0(transitive)
- Removedcross-spawn-async@2.2.5(transitive)
- Removedexeca@0.2.2(transitive)
- Removedis-path-inside@2.1.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removednpm-run-path@1.0.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedp-map@2.1.0(transitive)
- Removedpath-is-inside@1.0.2(transitive)
- Removedpath-key@1.0.0(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedstrip-eof@1.0.0(transitive)
- Removedwhich@1.3.1(transitive)
- Removedxdg-basedir@2.0.0(transitive)
- Removedxdg-trashdir@2.1.1(transitive)
- Removedyallist@2.1.2(transitive)
Updatedis-path-inside@^3.0.2
Updatedp-map@^3.0.0
Updatedxdg-trashdir@^3.1.0