aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2007-01-15 08:54:51 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2007-01-15 08:54:51 +0000
commite4b0666f8eee3fc48f37c0cd3fd194c27652173c (patch)
tree4b4b8ad37e86ec30c45952c364866d1be1437901
parent63f3ce6d9a26cb46a2f066dd9c5f2af25b3610df (diff)
* builtins.filterSource: pass the type of the file ("regular",
"directory", "symlink") as the second argument to the filter predicate.
-rw-r--r--src/libexpr/primops.cc19
-rw-r--r--tests/filter-source.nix.in4
-rw-r--r--tests/filter-source.sh2
3 files changed, 23 insertions, 2 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index bc6e290a4..270bc4446 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -7,6 +7,10 @@
#include "expr-to-xml.hh"
#include "nixexpr-ast.hh"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#include <algorithm>
@@ -739,7 +743,20 @@ struct FilterFromExpr : PathFilter
bool operator () (const Path & path)
{
- Expr call = makeCall(filter, makePath(toATerm(path)));
+ struct stat st;
+ if (lstat(path.c_str(), &st))
+ throw SysError(format("getting attributes of path `%1%'") % path);
+
+ Expr call =
+ makeCall(
+ makeCall(filter, makePath(toATerm(path))),
+ makeStr(
+ S_ISREG(st.st_mode) ? "regular" :
+ S_ISDIR(st.st_mode) ? "directory" :
+ S_ISLNK(st.st_mode) ? "symlink" :
+ "unknown" /* not supported, will fail! */
+ ));
+
return evalBool(state, call);
}
};
diff --git a/tests/filter-source.nix.in b/tests/filter-source.nix.in
index 2b5c23d31..8493835c2 100644
--- a/tests/filter-source.nix.in
+++ b/tests/filter-source.nix.in
@@ -3,5 +3,7 @@ derivation {
system = "@system@";
builder = "@shell@";
args = ["-e" "-x" (builtins.toFile "builder" "PATH=@testPath@; ln -s $input $out")];
- input = builtins.filterSource (path: baseNameOf (toString path) != "foo") ./test-tmp/filterin;
+ input =
+ let filter = path: type: type != "symlink" && baseNameOf (toString path) != "foo";
+ in builtins.filterSource filter ./test-tmp/filterin;
}
diff --git a/tests/filter-source.sh b/tests/filter-source.sh
index 4880969ba..96ccaedca 100644
--- a/tests/filter-source.sh
+++ b/tests/filter-source.sh
@@ -5,9 +5,11 @@ mkdir $TEST_ROOT/filterin
mkdir $TEST_ROOT/filterin/foo
touch $TEST_ROOT/filterin/foo/bar
touch $TEST_ROOT/filterin/xyzzy
+ln -s xyzzy $TEST_ROOT/filterin/link
$NIX_BIN_DIR/nix-build ./filter-source.nix -o $TEST_ROOT/filterout
set -x
test ! -e $TEST_ROOT/filterout/foo/bar
test -e $TEST_ROOT/filterout/xyzzy
+test ! -L $TEST_ROOT/filterout/link