Skip to content

Commit

Permalink
Handle a lot of files on Linux (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivolimasilva authored and sindresorhus committed Feb 26, 2018
1 parent 8c96d42 commit da155fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/linux.js
@@ -1,9 +1,11 @@
'use strict';
const os = require('os');
const path = require('path');
const fsExtra = require('fs-extra');
const pify = require('pify');
const uuid = require('uuid');
const xdgTrashdir = require('xdg-trashdir');
const pMap = require('p-map');

const fs = pify(fsExtra);

Expand All @@ -28,4 +30,4 @@ DeletionDate=${(new Date()).toISOString()}
});
}

module.exports = paths => Promise.all(paths.map(trash));
module.exports = paths => pMap(paths, trash, {concurrency: os.cpus().length});
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -42,6 +42,7 @@
"escape-string-applescript": "^2.0.0",
"fs-extra": "^0.30.0",
"globby": "^7.1.1",
"p-map": "^1.2.0",
"p-try": "^1.0.0",
"pify": "^3.0.0",
"run-applescript": "^3.0.0",
Expand Down
15 changes: 15 additions & 0 deletions test.js
Expand Up @@ -101,6 +101,21 @@ test('directories', async t => {
t.false(fs.existsSync(321));
});

(process.platform === 'linux' ? test : test.failing)('tons of files', async t => {
const FILE_COUNT = 5000;
const paths = [];
for (let i = 0; i < FILE_COUNT; i++) {
paths.push('file' + i);
fs.writeFileSync('file' + i, '');
}

await t.notThrows(m(paths));

for (let i = 0; i < FILE_COUNT; i++) {
t.false(fs.existsSync('file' + i));
}
});

test('symlinks', async t => {
fs.writeFileSync('aaa', '');
fs.symlinkSync('aaa', 'bbb');
Expand Down

0 comments on commit da155fa

Please sign in to comment.