cleanup rfs

This commit is contained in:
SrGooglo 2024-03-25 08:13:06 +01:00
parent b68c49118a
commit 98401fbf8d
2 changed files with 26 additions and 30 deletions

View File

@ -1,29 +1,9 @@
import path from "node:path" import path from "node:path"
import fs from "node:fs" import fs from "node:fs"
import { execa } from "../../lib/execa" import { execa } from "../../lib/execa"
import Vars from "../../vars" import Vars from "../../vars"
async function readDirRecurse(dir, maxDepth=3, current = 0) {
if (current > maxDepth) {
return []
}
const files = await fs.promises.readdir(dir)
const promises = files.map(async (file) => {
const filePath = path.join(dir, file)
const stat = await fs.promises.stat(filePath)
if (stat.isDirectory()) {
return readDirRecurse(filePath, maxDepth, current + 1)
}
return filePath
})
return (await Promise.all(promises)).flat()
}
export default class RFS { export default class RFS {
constructor(manifest) { constructor(manifest) {
this.manifest = manifest this.manifest = manifest
@ -58,15 +38,6 @@ export default class RFS {
stderr: "inherit", stderr: "inherit",
}) })
await new Promise((r) => {
setTimeout(r, 1000)
})
// // try to read from the mount point
// let dirs = await readDirRecurse(mountPoint)
// console.log(dirs)
if (typeof cb === "function") { if (typeof cb === "function") {
cb(process) cb(process)
} }

View File

@ -0,0 +1,25 @@
import fs from "node:fs"
import path from "node:path"
async function readDirRecurse(dir, maxDepth = 3, current = 0) {
if (current > maxDepth) {
return []
}
const files = await fs.promises.readdir(dir)
const promises = files.map(async (file) => {
const filePath = path.join(dir, file)
const stat = await fs.promises.stat(filePath)
if (stat.isDirectory()) {
return readDirRecurse(filePath, maxDepth, current + 1)
}
return filePath
})
return (await Promise.all(promises)).flat()
}
export default readDirRecurse