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.
38 lines
1003 B
JavaScript
38 lines
1003 B
JavaScript
"use strict";
|
|
|
|
const memoizee = require("memoizee");
|
|
const fs = require("fs").promises;
|
|
const findmnt = require("../exec-findmnt");
|
|
const All = require("../graphql-interface/symbols/all");
|
|
const treeMapAsync = require("../tree-map-async");
|
|
const treeFind = require("../tree-find");
|
|
|
|
module.exports = function () {
|
|
let findmntOnce = memoizee(async () => {
|
|
return treeMapAsync(await findmnt(), async (mount) => {
|
|
return {
|
|
... mount,
|
|
sourceDevice: (mount.sourceDevice?.startsWith("/"))
|
|
? await fs.realpath(mount.sourceDevice)
|
|
: mount.sourceDevice
|
|
};
|
|
|
|
});
|
|
});
|
|
|
|
return async function (mountpoints) {
|
|
let mounts = await findmntOnce();
|
|
|
|
// TODO: It's kind of strange that it sometimes returns a tree and sometimes a list, this can probably be improved?
|
|
let matches = mountpoints.map((mountpoint) => {
|
|
if (mountpoint === All) {
|
|
return mounts;
|
|
} else {
|
|
return treeFind(mounts, (mount) => mount.mountpoint === mountpoint);
|
|
}
|
|
});
|
|
|
|
return matches;
|
|
};
|
|
};
|