1
0
This commit is contained in:
Zef Hemel 2022-11-29 08:50:09 +01:00
parent 299e2446b0
commit 55791cc88e

View File

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