sindresorhus / trash

Move files and directories to the trash
MIT License
2.57k stars 78 forks source link

Contribution 😬: Perhaps 'procfs' dependency isn't really needed? #125

Open nocke opened 1 year ago

nocke commented 1 year ago

Perhaps 'procfs' dependency isn't really needed? ( procfs can certainly do a lot, but we only need rather little )

IMHO, this should suffice, to get all the parsing info needed under linux: (already with heavy filtering as in PR 124)

const getMount = (mountId, _parentID, _deviceNo, root, mountPoint, mountOptions, _fields, _mountSource, superOptions, blob) => (
  {
    mountId,
    // parentID,
    // deviceNo,
    root,
    mountPoint,
    mountOptions: mountOptions.split(','),
    // fields,
    // mountSource,
    superOptions: superOptions.split(','),
    blob
  })

const mounts = fs.readFileSync('/proc/self/mountinfo', 'utf-8')
mounts.split(/\n/)
  .filter(l => l.length > 0) // filter empty line at end
  .map((m) => getMount(...m.split(' ')))
  .filter((m) =>
    !/^\/(snap|run|sys|proc|dev)($|\/)/.test(m.mountPoint) &&
      !['mqueue', 'tmpfs'].includes(m.superOptions) &&
      !m.superOptions.includes('mqueue') &&
      !m.superOptions.includes('tmpfs') &&
      !m.mountOptions.includes('ro')
  )
  .map((l) =>
    info(l))
sindresorhus commented 1 year ago

I would prefer to keep the dependency. I don't really want to maintain this code. From experience, there are definitely edge-cases that will present itself later on.