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.
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
const fs = Promise.promisifyAll(require("fs"));
|
|
const dlayerSource = require("../../packages/dlayer-source");
|
|
const types = require("./");
|
|
|
|
module.exports = function Mount({ mountpoint }) {
|
|
return dlayerSource.withSources({
|
|
mountpoint: mountpoint,
|
|
sourceDevice: async (_, { sources }) => {
|
|
let mount = await sources.findmnt.load(mountpoint);
|
|
|
|
if (mount != null) {
|
|
if (mount.sourceDevice != null) {
|
|
let sourcePath = await fs.realpathAsync(mount.sourceDevice);
|
|
|
|
if (await sources.lsblk.load({ path: sourcePath }) != null) {
|
|
return types.BlockDevice({ path: sourcePath });
|
|
} else {
|
|
// This occurs when the `sourceDevice` is a valid device, but it is not a *block* device, eg. `/dev/fuse`
|
|
return null;
|
|
}
|
|
} else {
|
|
// This occurs when the mount is not backed by a device, eg. an sshfs FUSE mount
|
|
return null;
|
|
}
|
|
} else {
|
|
// TODO: Can this ever happen for any legitimate reason?
|
|
throw new Error(`Mountpoint '${mountpoint}' not found in findmnt output`);
|
|
}
|
|
},
|
|
$sources: {
|
|
findmnt: {
|
|
[dlayerSource.ID]: mountpoint,
|
|
id: "id",
|
|
// FIXME: Aren't we inferring the below somewhere else in the code, using the square brackets?
|
|
type: (mount) => (mount.rootPath === "/")
|
|
? "ROOT_MOUNT"
|
|
: "SUBMOUNT",
|
|
filesystem: "filesystem",
|
|
options: "options",
|
|
label: "label",
|
|
uuid: "uuid",
|
|
partitionLabel: "partitionLabel",
|
|
partitionUUID: "partitionUUID",
|
|
deviceNumber: "deviceNumber",
|
|
totalSpace: "totalSpace",
|
|
freeSpace: "freeSpace",
|
|
usedSpace: "usedSpace",
|
|
rootPath: "rootPath",
|
|
taskID: "taskID",
|
|
optionalFields: "optionalFields",
|
|
propagationFlags: "propagationFlags",
|
|
children: (mount) => mount.children.map((child) => {
|
|
return Mount({ mountpoint: child.mountpoint });
|
|
})
|
|
}
|
|
}
|
|
});
|
|
};
|