Skip to content

Commit

Permalink
Fix finding the trash directory on Linux (#124)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
nocke and sindresorhus committed Feb 11, 2023
1 parent 24cd5c1 commit 32d148a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/linux.js
Expand Up @@ -38,7 +38,20 @@ const trash = async (filePath, trashPaths) => {
};

export default async function linux(paths) {
const mountPointMap = new Map(procfs.processMountinfo().map(info => [info.devId, info.mountPoint]));
const mountPointMap = new Map();

for (const mountInfo of Object.values(procfs.processMountinfo())) {
// Filter out irrelevant drives (that start with `/snap`, `/run`, etc).
if (/^\/(snap|var\/snap|run|sys|proc|dev)($|\/)/.test(mountInfo.mountPoint)) {
continue;
}

// Keep the first one if there are multiple `devId`.
if (!mountPointMap.has(mountInfo.devId)) {
mountPointMap.set(mountInfo.devId, mountInfo.mountPoint);
}
}

const trashPathsCache = new Map();

const getDeviceTrashPaths = async devId => {
Expand Down

0 comments on commit 32d148a

Please sign in to comment.