"use strict"; const Promise = require("bluebird"); const memoizee = require("memoizee"); const linearizeTree = require("../../linearize-tree"); const lsblk = require("../../wrappers/lsblk"); const All = require("../../graphql/symbols/all"); module.exports = function () { let lsblkOnce = memoizee(() => { return Promise.try(() => { return lsblk(); }).then((devices) => { return { tree: devices, list: linearizeTree(devices) }; }); }); return function (names) { return Promise.try(() => { return lsblkOnce(); }).then(({tree, list}) => { return names.map((name) => { if (name === All) { return tree; } else { return list.find((device) => device.name === name); } }); }); }; };