Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filterSource support #34

Merged
merged 3 commits into from Apr 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/logged-evaluation.nix
Expand Up @@ -13,6 +13,24 @@ let
builtins = builtins // {
readFile = file: builtins.trace "lorri read: '${toString file}'" (builtins.readFile file);
readDir = path: builtins.trace "lorri readdir: '${toString path}'" (builtins.readDir path);
filterSource = fn: path: let
# use the filter function to check which of the direct children of path should be watched
# this allow to ignore usual suspects like .git or a top-level result symlink
file_type = builtins.readDir path;
# list of files
files = builtins.attrNames file_type;
# list of kept files
kept = builtins.filter (name: fn "${toString path}/${name}" file_type.${name}) files;
# whether all files were kept
all_kept = builtins.length kept == builtins.length files;
# the actual value we must return
result = builtins.filterSource fn path;
# if all files were kept, let's log only ${path}
logTopLevel = builtins.trace "lorri read: '${toString path}'" result;
# otherwise log all kept files individually, and the listing of the toplevel dir
log1stLevel = builtins.trace "lorri readdir: '${toString path}'" (builtins.foldl' (acc: name: builtins.trace "lorri read: '${toString path}/${name}'" acc) result kept);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the tradeoff right? If a recursive directory is kept, it will be watched recursively.

Still, in combination with the previous commit a strict improvement!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, not quite. input sources were still watched 100%, so both commits are an improvement to the filtering logic. Awesome.

in
if all_kept then logTopLevel else log1stLevel;
};
};

Expand Down