numtide / nix-filter

a small self-contained source filtering lib
MIT License
200 stars 17 forks source link

Don't match parents while excluding a path #13

Closed ilkecan closed 2 years ago

ilkecan commented 2 years ago

Given the following directory

$ tree
.
├── data
│   ├── a
│   ├── b
│   └── c
├── flake.lock
└── flake.nix

The following nix-filter call was producing an empty directory:

let
  inherit (nix-filter) inDirectory;
in
nix-filter {
  root = ./.;
  name = "test";
  include = [
    (inDirectory "data")
  ];
  exclude = [
    "data/a"
  ];
}

Because of this line https://github.com/numtide/nix-filter/blob/3c9e33ed627e009428197b07216613206f06ed80/default.nix#L35

In essence, it is changed to

        path_ == path
        || args.matchParents
          && type == "directory"
          && _hasPrefix "${path}/" path_;

where args.matchParents is true for include and false for exclude.

ilkecan commented 2 years ago

I removed some stylistic changes so the diff should be smaller now.

zimbatm commented 2 years ago

nice, thanks for tackling this issue