From 55791cc88ebced8e0b33166be1337156b77c316a Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 29 Nov 2022 08:50:09 +0100 Subject: [PATCH] Fixes #130 --- common/spaces/disk_space_primitives.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/spaces/disk_space_primitives.ts b/common/spaces/disk_space_primitives.ts index 5907e55f..44200cf1 100644 --- a/common/spaces/disk_space_primitives.ts +++ b/common/spaces/disk_space_primitives.ts @@ -155,7 +155,11 @@ export class DiskSpacePrimitives implements SpacePrimitives { const file of walk(this.rootPath, { includeDirs: false, // Exclude hidden directories - 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) + new RegExp(`^${escapeRegExp(this.rootPath)}.*\\/\\..+$`), + ], }) ) { const fullPath = file.path; @@ -194,3 +198,7 @@ export class DiskSpacePrimitives implements SpacePrimitives { return plug.syscall(name, args); } } + +function escapeRegExp(string: string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string +}