Skip to content

Ignored files are not excluded from key listing #621

@odzhychko

Description

@odzhychko

Environment

Tested with unstorage v1.15.0

Reproduction

import { createStorage } from "unstorage";
import fsDriver from "unstorage/drivers/fs";
import { writeFile, mkdir } from "fs/promises";
import { join } from "path";

const testFolders = join("dir1", "dir2");
await mkdir(testFolders, { recursive: true });

const storage = await createStorage({
  driver: fsDriver({
    base: "./dir1",
    ignore: "**/dir2/test.txt",
  }),
});

await writeFile("./dir1/dir2/test.txt", "");

console.log(await storage.getKeys());

This code outputs [ 'dir2:test.txt' ] but I would expect it to output [].

Describe the bug

When creating a fsDriver a ignore patterns can be specified.

When listing keys with getKeys files that match an ignore pattern are still returned in some cases.
This happens if the parent path of the file does not match an ignore pattern.

The ignore pattern still correctly excludes files from being watched for changes.
So it appears that the ignore patterns are applied correctly when setting up file watching, but not when applied for listing keys.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions