about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-10-17T11·05+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-10-17T11·05+0000
commitcba913c5217fd4071419279da81fd02599715b6a (patch)
tree42244c6de9b9dbb105c7cfaa5874e12777ff376d /src/libexpr/primops.cc
parentcf705eaf78df646116f2fc14e6fa07d88f1607fe (diff)
* dirOf: return a path if the argument is a path.
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 536345f229..6b4858d800 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -316,11 +316,15 @@ static Expr primBaseNameOf(EvalState & state, const ATermVector & args)
 
 
 /* Return the directory of the given path, i.e., everything before the
-   last slash. */
+   last slash.  Return either a path or a string depending on the type
+   of the argument. */
 static Expr primDirOf(EvalState & state, const ATermVector & args)
 {
     PathSet context;
-    return makeStr(dirOf(coerceToPath(state, args[0], context)), context);
+    Expr e = evalExpr(state, args[0]); ATerm dummy;
+    bool isPath = matchPath(e, dummy);
+    Path dir = dirOf(coerceToPath(state, e, context));
+    return isPath ? makePath(toATerm(dir)) : makeStr(dir, context);
 }