Skip to content

Commit

Permalink
refactor: add catch in case of failure
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Gillespie <[email protected]>
  • Loading branch information
goller and jacobwgillespie authored May 15, 2024
1 parent 8e69734 commit 9c3d942
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/utils/mounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,23 @@ interface FileSystems {
// Returns the paths of all overlayfs mounts that are children of the given path.
// This is useful to unmount all child mounts before unmounting the parent.
export async function findOverlayPaths(path: string): Promise<string[]> {
const {stdout} = await execa('findmnt', ['-R', '-J', path])
const fs: FileSystems = JSON.parse(stdout)
if (fs.filesystems.length === 0) {
return []
}
try {
const {stdout} = await execa('findmnt', ['-R', '-J', path])
const fs: FileSystems = JSON.parse(stdout)
if (fs.filesystems.length === 0) {
return []
}

const childTargets = new Set<string>()
fs.filesystems.forEach((f) => {
if (f.children) {
f.children.forEach((c) => childTargets.add(c.target))
const childTargets = new Set<string>()
for (const f of fs.filesystems) {
for (const c of f.children ?? []) {
childTargets.add(c.target)
}
}
})

return Array.from(childTargets)
return Array.from(childTargets)
} catch (err) {
console.error('Failed to run findmnt', err)
return []
}
}

0 comments on commit 9c3d942

Please sign in to comment.