You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
const memoizee = require("memoizee");
|
|
const fs = Promise.promisifyAll(require("fs"));
|
|
const findmnt = require("../../packages/exec-findmnt");
|
|
const All = require("../../packages/graphql-interface/symbols/all");
|
|
const treeMapAsync = require("../../packages/tree-map-async");
|
|
|
|
module.exports = function () {
|
|
let findmntOnce = memoizee(() => {
|
|
return Promise.try(() => {
|
|
return findmnt();
|
|
}).then((mounts) => {
|
|
return treeMapAsync(mounts, async (mount) => {
|
|
if (mount.sourceDevice?.startsWith("/")) {
|
|
return {
|
|
... mount,
|
|
sourceDevice: await fs.realpathAsync(mount.sourceDevice)
|
|
};
|
|
} else {
|
|
// Skip mounts that don't exist at a path at all
|
|
return mount;
|
|
}
|
|
}, true);
|
|
});
|
|
});
|
|
|
|
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);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
};
|