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 +}