fs: Add sub-temp and mount APIs
This commit is contained in:
parent
69d6f0e50f
commit
4c69202c7e
1 changed files with 15 additions and 0 deletions
|
@ -9,6 +9,7 @@ const TMP_PREFIX = 'adevtool-'
|
||||||
export interface TempState {
|
export interface TempState {
|
||||||
dir: string
|
dir: string
|
||||||
mounts: Array<string>
|
mounts: Array<string>
|
||||||
|
rootTmp?: TempState
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/a/45130990
|
// https://stackoverflow.com/a/45130990
|
||||||
|
@ -58,6 +59,20 @@ export async function withTempDir<Return>(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) {
|
export async function readFile(path: string) {
|
||||||
return await fs.readFile(path, { encoding: 'utf8' })
|
return await fs.readFile(path, { encoding: 'utf8' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function mount(imgPath: string, mountpoint: string) {
|
||||||
|
await run(`mount -t ext4 -o ro ${imgPath} ${mountpoint}`)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue