diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-01-15T08·54+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-01-15T08·54+0000 |
commit | e4b0666f8eee3fc48f37c0cd3fd194c27652173c (patch) | |
tree | 4b4b8ad37e86ec30c45952c364866d1be1437901 /src/libexpr | |
parent | 63f3ce6d9a26cb46a2f066dd9c5f2af25b3610df (diff) |
* builtins.filterSource: pass the type of the file ("regular",
"directory", "symlink") as the second argument to the filter predicate.
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/primops.cc | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index bc6e290a48fc..270bc4446bff 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); } }; |