From bdb4159f5bc92f11ffcd10ff4f2649b090d63cee Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 21 Nov 2023 12:05:17 +0100 Subject: [PATCH] Fixes #518 --- plugos/syscalls/fs.deno.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugos/syscalls/fs.deno.ts b/plugos/syscalls/fs.deno.ts index 5c419e0c..4c5eb3a7 100644 --- a/plugos/syscalls/fs.deno.ts +++ b/plugos/syscalls/fs.deno.ts @@ -78,7 +78,11 @@ export default function fileSystemSyscalls(root = "/"): SysCallMapping { const file of walk(dirPath, { includeDirs: false, // Exclude hidden files - skip: [/^.*\/\..+$/], + skip: [ + // Dynamically builds a regexp that matches hidden directories INSIDE the rootPath + // (but if the rootPath is hidden, it stil lists files inside of it, fixing #130 and #518) + new RegExp(`^${escapeRegExp(root)}.*\\/\\..+$`), + ], maxDepth: recursive ? Infinity : 1, }) ) { @@ -97,3 +101,7 @@ export default function fileSystemSyscalls(root = "/"): SysCallMapping { }, }; } + +function escapeRegExp(string: string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string +}