From 83a82a22e508d40f36f0d5345b8e4e497fa21c32 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 29 Jan 2007 14:53:23 +0000 Subject: [PATCH] * Filter out *~ files in cleanSource. svn path=/nixpkgs/trunk/; revision=7803 --- pkgs/lib/default.nix | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pkgs/lib/default.nix b/pkgs/lib/default.nix index 32b20769647..e0c96c2395b 100644 --- a/pkgs/lib/default.nix +++ b/pkgs/lib/default.nix @@ -2,7 +2,8 @@ let - inherit (builtins) head tail isList; + inherit (builtins) + head tail isList stringLength substring lessThan sub; in @@ -81,13 +82,24 @@ rec { else if xs == [] || ys == [] then false else head xs == head ys && eqLists (tail xs) (tail ys); - - # Bring in a path as a source, filtering out all hidden Subversion - # directories. TODO: filter out backup files (*~) etc. + + # Determine whether a filename ends in the given suffix. + hasSuffix = ext: fileName: + let lenFileName = stringLength fileName; + lenExt = stringLength ext; + in !(lessThan lenFileName lenExt) && + substring (sub lenFileName lenExt) lenFileName fileName == ext; + + + # Bring in a path as a source, filtering out all Subversion and CVS + # directories, as well as backup files (*~). cleanSource = - let filter = name: type: - type != "directory" - || baseNameOf (toString name) != ".svn"; + let filter = name: type: let baseName = baseNameOf (toString name); in ! ( + # Filter out Subversion and CVS directories. + (type == "directory" && (name == ".svn" || name == "CVS")) || + # Filter out backup files. + (hasSuffix "~" name) + ); in src: builtins.filterSource filter src;