about summary refs log tree commit diff
diff options
context:
space:
mode:
authoredef <edef@mutable.io>2020-05-28T12·51+0000
committeredef <edef@edef.eu>2020-06-13T20·08+0000
commitcec109807babe65dba79b9776cee2024aad349a6 (patch)
tree54854dc37d159bbd309144408fa3f97a411a283e
parentcbcec9fd04f0e317d4e7026c6ee43217c7d75c86 (diff)
fix(nix/readTree): Ignore hidden files and directories r/939
This skips any directory entries starting with a dot.

Change-Id: I95767f3d35bcb2ed9b3d6e772f3924dd57612711
Reviewed-on: https://cl.tvl.fyi/c/depot/+/123
Reviewed-by: tazjin <mail@tazj.in>
-rw-r--r--nix/readTree/default.nix17
1 files changed, 14 insertions, 3 deletions
diff --git a/nix/readTree/default.nix b/nix/readTree/default.nix
index c48928ee19e4..4faf20d9e5c0 100644
--- a/nix/readTree/default.nix
+++ b/nix/readTree/default.nix
@@ -9,17 +9,28 @@ let
     filter
     hasAttr
     head
+    isAttrs
     length
     listToAttrs
     map
     match
-    isAttrs
-    readDir;
+    readDir
+    substring;
 
   argsWithPath = parts: args // {
     locatedAt = parts;
   };
 
+  readDirVisible = path:
+    let
+      children = readDir path;
+      isVisible = f: f == ".skip-subtree" || (substring 0 1 f) != ".";
+      names = filter isVisible (attrNames children);
+    in listToAttrs (map (name: {
+      inherit name;
+      value = children.${name};
+    }) names);
+
   # The marker is added to every set that was imported directly by
   # readTree.
   importWithMark = path: parts:
@@ -34,7 +45,7 @@ let
 
   readTree = path: parts:
     let
-      dir = readDir path;
+      dir = readDirVisible path;
       self = importWithMark path parts;
       joinChild = c: path + ("/" + c);