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