forked from lix-project/lix
* New primop `readFile' to get the contents of a file as a string.
This commit is contained in:
parent
c370755583
commit
06f95dd07c
|
@ -441,6 +441,15 @@ in config.someSetting</programlisting>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
<varlistentry><term><function>builtins.readFile</function>
|
||||||
|
<replaceable>path</replaceable></term>
|
||||||
|
|
||||||
|
<listitem><para>Return the contents of the file
|
||||||
|
<replaceable>path</replaceable> as a string.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
|
||||||
<varlistentry><term><function>removeAttrs</function>
|
<varlistentry><term><function>removeAttrs</function>
|
||||||
<replaceable>attrs</replaceable> <replaceable>list</replaceable></term>
|
<replaceable>attrs</replaceable> <replaceable>list</replaceable></term>
|
||||||
|
|
||||||
|
|
|
@ -622,6 +622,17 @@ static Expr prim_dirOf(EvalState & state, const ATermVector & args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return the contents of a file as a string. */
|
||||||
|
static Expr prim_readFile(EvalState & state, const ATermVector & args)
|
||||||
|
{
|
||||||
|
PathSet context;
|
||||||
|
Path path = coerceToPath(state, args[0], context);
|
||||||
|
if (!context.empty())
|
||||||
|
throw EvalError(format("string `%1%' cannot refer to other paths") % path);
|
||||||
|
return makeStr(readFile(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Creating files
|
* Creating files
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
|
@ -968,6 +979,7 @@ void EvalState::addPrimOps()
|
||||||
addPrimOp("__pathExists", 1, prim_pathExists);
|
addPrimOp("__pathExists", 1, prim_pathExists);
|
||||||
addPrimOp("baseNameOf", 1, prim_baseNameOf);
|
addPrimOp("baseNameOf", 1, prim_baseNameOf);
|
||||||
addPrimOp("dirOf", 1, prim_dirOf);
|
addPrimOp("dirOf", 1, prim_dirOf);
|
||||||
|
addPrimOp("__readFile", 1, prim_readFile);
|
||||||
|
|
||||||
// Creating files
|
// Creating files
|
||||||
addPrimOp("__toXML", 1, prim_toXML);
|
addPrimOp("__toXML", 1, prim_toXML);
|
||||||
|
|
1
tests/lang/eval-okay-readfile.exp
Normal file
1
tests/lang/eval-okay-readfile.exp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Str("builtins.readFile ./eval-okay-readfile.nix\n",[])
|
1
tests/lang/eval-okay-readfile.nix
Normal file
1
tests/lang/eval-okay-readfile.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
builtins.readFile ./eval-okay-readfile.nix
|
Loading…
Reference in a new issue