Skip to content

Commit abe09a2

Browse files
committed
Minor tweaks
1 parent d55ea00 commit abe09a2

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

lib/linux.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export default async function linux(paths) {
5454

5555
const trashPathsCache = new Map();
5656

57-
const getDeviceTrashPaths = async developmentId => {
58-
let trashPathsPromise = trashPathsCache.get(developmentId);
57+
const getDeviceTrashPaths = async deviceId => {
58+
let trashPathsPromise = trashPathsCache.get(deviceId);
5959
if (!trashPathsPromise) {
6060
trashPathsPromise = (async () => {
61-
const trashPath = await xdgTrashdir(mountPointMap.get(developmentId));
61+
const trashPath = await xdgTrashdir(mountPointMap.get(deviceId));
6262
const paths = {
6363
filesPath: path.join(trashPath, 'files'),
6464
infoPath: path.join(trashPath, 'info'),
@@ -67,7 +67,7 @@ export default async function linux(paths) {
6767
await fs.promises.mkdir(paths.infoPath, {mode: 0o700, recursive: true});
6868
return paths;
6969
})();
70-
trashPathsCache.set(developmentId, trashPathsPromise);
70+
trashPathsCache.set(deviceId, trashPathsPromise);
7171
}
7272

7373
return trashPathsPromise;

test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,39 @@ test('glob with nested directories', async () => {
195195
assert.ok(!fs.existsSync(directory2));
196196
assert.ok(!fs.existsSync(directory3));
197197
});
198+
199+
test('empty array', async () => {
200+
await assert.doesNotReject(trash([]));
201+
});
202+
203+
test('mixed existing and non-existing files', async () => {
204+
fs.writeFileSync('exists1', '');
205+
fs.writeFileSync('exists2', '');
206+
assert.ok(fs.existsSync('exists1'));
207+
assert.ok(fs.existsSync('exists2'));
208+
assert.ok(!fs.existsSync('does-not-exist'));
209+
210+
await trash(['exists1', 'does-not-exist', 'exists2']);
211+
212+
assert.ok(!fs.existsSync('exists1'));
213+
assert.ok(!fs.existsSync('exists2'));
214+
assert.ok(!fs.existsSync('does-not-exist'));
215+
});
216+
217+
test('single file path', async () => {
218+
fs.writeFileSync('single-file', '');
219+
assert.ok(fs.existsSync('single-file'));
220+
221+
await trash('single-file');
222+
223+
assert.ok(!fs.existsSync('single-file'));
224+
});
225+
226+
test('empty directory', async () => {
227+
fs.mkdirSync('empty-dir');
228+
assert.ok(fs.existsSync('empty-dir'));
229+
230+
await trash('empty-dir');
231+
232+
assert.ok(!fs.existsSync('empty-dir'));
233+
});

0 commit comments

Comments
 (0)