sindresorhus / trash

Move files and directories to the trash
MIT License
2.58k stars 79 forks source link

Fix glob for nested directories #80

Closed medusalix closed 5 years ago

medusalix commented 5 years ago

Makes it possible to use the option glob with nested directories through sorting the filepaths by their depth before passing them to the trash function.

Fixes #75

sindresorhus commented 5 years ago

This way works fine, but I had another idea in mind. If we have ['foo', 'foo/bar', 'foo/baz'], couldn't we just remove foo/bar and foo/baz? As foo will remove those anyway. I think this would help speed up the deletion process too and reduce the situations where users encounter https://github.com/sindresorhus/trash-cli/issues/9.

medusalix commented 5 years ago

@sindresorhus Your proposed solution is actually slower the way I have implemented it 😄. I traverse the whole array for each item to check if there's already a directory above it.

To be honest, I think the operation system is much quicker at moving files to the trash than JS is at de-duplicating an array.

sindresorhus commented 5 years ago

Your proposed solution is actually slower the way I have implemented it

How was that measured? The difference is probably negligible for macOS, but for Linux we actually remove each file using JS, so I think my solution would be more efficient then.

To be honest, I think the operation system is much quicker at moving files to the trash than JS is at de-duplicating an array.

I highly doubt that.