Skip to content

Commit

Permalink
fix(api): host drive did not collect all partition infos
Browse files Browse the repository at this point in the history
fixes #277
  • Loading branch information
MauriceNino committed Aug 16, 2022
1 parent b6c8135 commit 3caa68f
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions apps/api/src/dynamic-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,38 @@ export const getDynamicServerInfo = () => {
const deviceParts = validParts.filter(({ name }) =>
name.startsWith(device)
);
const potentialHost =
// drives that have all partitions unmounted
deviceParts.every(
({ mount }) => mount == null || !mount.startsWith('/mnt/host/')
) ||
const explicitHost =
// drives where one of the partitions is mounted to the root or /mnt/host/boot/
deviceParts.some(
({ mount }) =>
mount === '/mnt/host' || mount.startsWith('/mnt/host/boot/')
);
const potentialHost =
// drives that have all partitions unmounted
deviceParts.every(
({ mount }) => mount == null || !mount.startsWith('/mnt/host/')
) ||
// if there is only one drive, it has to be the host
storageLayout.length === 1;

if (explicitHost || !potentialHost) {
if (explicitHost) {
hostFound = true;
}

return deviceParts.reduce(
(acc, curr) =>
acc +
(validMounts.find(({ mount }) => curr.mount === mount)
?.used ?? 0),
0
);
}

// Apply all unclaimed partitions to the host disk
if (potentialHost && !hostFound) {
hostFound = true;

const unclaimedSpace = validMounts
.filter(
({ mount }) => !validParts.some(part => part.mount === mount)
Expand All @@ -153,15 +169,7 @@ export const getDynamicServerInfo = () => {
return hostMountUsed + unclaimedSpace;
}

return potentialHost
? 0
: deviceParts.reduce(
(acc, curr) =>
acc +
(validMounts.find(({ mount }) => curr.mount === mount)
?.used ?? 0),
0
);
return 0;
})
.map(used => ({
load: used,
Expand Down

0 comments on commit 3caa68f

Please sign in to comment.