Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Jul 24, 2024
1 parent 48311c9 commit 43a3fb5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions libs/langchain-scripts/src/build_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const deleteFolderRecursive = async function (inputPath: string) {
.catch(() => false)
) {
const files = await fs.promises.readdir(inputPath);
for (const file of files) {
for await (const file of files) {
const curPath = path.join(inputPath, file);
if ((await fs.promises.lstat(curPath)).isDirectory()) {
// recurse
Expand All @@ -45,7 +45,14 @@ const deleteFolderRecursive = async function (inputPath: string) {
await fs.promises.unlink(curPath);
}
}
await fs.promises.rmdir(inputPath);

// Verify again that the directory is empty
const filesAfter = await fs.promises.readdir(inputPath);
if (filesAfter.length === 0) {
await fs.promises.rmdir(inputPath);
} else {
throw new Error(`Failed to delete ${inputPath} because dir is not empty`);
}
}
};

Expand Down

0 comments on commit 43a3fb5

Please sign in to comment.