diff --git a/src/util/fs.ts b/src/util/fs.ts index 99527eb..bc3e1fe 100644 --- a/src/util/fs.ts +++ b/src/util/fs.ts @@ -9,6 +9,7 @@ const TMP_PREFIX = 'adevtool-' export interface TempState { dir: string mounts: Array + rootTmp?: TempState } // https://stackoverflow.com/a/45130990 @@ -58,6 +59,20 @@ export async function withTempDir(callback: (tmp: TempState) => Promise< } } +export async function createSubTmp(tmp: TempState, subpath: string) { + await fs.mkdir(`${tmp.dir}/${subpath}`, { recursive: true }) + + return { + ...tmp, + dir: `${tmp.dir}/${subpath}`, + rootTmp: tmp.rootTmp ?? tmp, + } as TempState +} + export async function readFile(path: string) { return await fs.readFile(path, { encoding: 'utf8' }) } + +export async function mount(imgPath: string, mountpoint: string) { + await run(`mount -t ext4 -o ro ${imgPath} ${mountpoint}`) +}