"use strict"; const Promise = require("bluebird"); const memoizee = require("memoizee"); const fs = Promise.promisifyAll(require("fs")); const treecutter = require("../../packages/treecutter"); const findmnt = require("../../packages/exec-findmnt"); const shallowMerge = require("../../packages/shallow-merge"); const All = require("../../packages/graphql-interface/symbols/all"); module.exports = function () { let findmntOnce = memoizee(() => { return Promise.try(() => { return findmnt(); }).then((mounts) => { return treecutter.flatten(mounts); }).map((mount) => { if (mount.sourceDevice?.startsWith("/")) { return Promise.try(() => { return fs.realpathAsync(mount.sourceDevice); }).then((actualSourcePath) => { return shallowMerge(mount, { sourceDevice: actualSourcePath }); }); } else { return mount; } }).then((list) => { let tree = treecutter.rebuild(list); return { tree: tree, list: list }; }); }); return function (mountpoints) { return Promise.try(() => { return findmntOnce(); }).then(({tree, list}) => { return mountpoints.map((mountpoint) => { if (mountpoint === All) { return tree; } else { return list.find((mount) => mount.mountpoint === mountpoint); } }); }); }; };