From 98401fbf8dd5d56fba71f36fbbe996ce90b1feb8 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Mon, 25 Mar 2024 08:13:06 +0100 Subject: [PATCH] cleanup rfs --- src/main/lib/rfs/index.js | 31 +------------------------------ src/main/utils/readDirRecurse.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 30 deletions(-) create mode 100644 src/main/utils/readDirRecurse.js diff --git a/src/main/lib/rfs/index.js b/src/main/lib/rfs/index.js index 4461cd5..de15366 100644 --- a/src/main/lib/rfs/index.js +++ b/src/main/lib/rfs/index.js @@ -1,29 +1,9 @@ import path from "node:path" import fs from "node:fs" import { execa } from "../../lib/execa" + 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 { constructor(manifest) { this.manifest = manifest @@ -57,15 +37,6 @@ export default class RFS { stdout: "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") { cb(process) diff --git a/src/main/utils/readDirRecurse.js b/src/main/utils/readDirRecurse.js new file mode 100644 index 0000000..342dda0 --- /dev/null +++ b/src/main/utils/readDirRecurse.js @@ -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 \ No newline at end of file