Merge branch 'readfile' of https://github.com/abbradar/nix
This commit is contained in:
commit
f39d94a55b
5 changed files with 43 additions and 2 deletions
|
@ -1470,7 +1470,11 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
string s = readFile(path);
|
||||
if (s.find((char) 0) != string::npos)
|
||||
throw Error("the contents of the file '%1%' cannot be represented as a Nix string", path);
|
||||
v.mkString(s);
|
||||
auto refs = state.store->isInStore(path) ?
|
||||
state.store->queryPathInfo(state.store->toStorePath(path).first)->references :
|
||||
StorePathSet{};
|
||||
auto context = state.store->printStorePathSet(refs);
|
||||
v.mkString(s, context);
|
||||
}
|
||||
|
||||
static RegisterPrimOp primop_readFile({
|
||||
|
|
|
@ -59,7 +59,8 @@ nix_tests = \
|
|||
ca/recursive.sh \
|
||||
ca/concurrent-builds.sh \
|
||||
ca/nix-copy.sh \
|
||||
eval-store.sh
|
||||
eval-store.sh \
|
||||
readfile-context.sh
|
||||
# parallel.sh
|
||||
|
||||
ifeq ($(HAVE_LIBCPUID), 1)
|
||||
|
|
1
tests/readfile-context.builder.sh
Normal file
1
tests/readfile-context.builder.sh
Normal file
|
@ -0,0 +1 @@
|
|||
echo "$input" > $out
|
19
tests/readfile-context.nix
Normal file
19
tests/readfile-context.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
with import ./config.nix;
|
||||
|
||||
let
|
||||
|
||||
input = import ./simple.nix;
|
||||
|
||||
dependent = mkDerivation {
|
||||
name = "dependent";
|
||||
builder = ./readfile-context.builder.sh;
|
||||
input = "${input}/hello";
|
||||
};
|
||||
|
||||
readDependent = mkDerivation {
|
||||
name = "read-dependent";
|
||||
builder = ./readfile-context.builder.sh;
|
||||
input = builtins.readFile dependent;
|
||||
};
|
||||
|
||||
in readDependent
|
16
tests/readfile-context.sh
Normal file
16
tests/readfile-context.sh
Normal file
|
@ -0,0 +1,16 @@
|
|||
source common.sh
|
||||
|
||||
clearStore
|
||||
|
||||
outPath=$(nix-build --no-out-link readfile-context.nix)
|
||||
|
||||
# Set a GC root.
|
||||
ln -s $outPath "$NIX_STATE_DIR"/gcroots/foo
|
||||
|
||||
# Check that file exists.
|
||||
[ "$(cat $(cat $outPath))" = "Hello World!" ]
|
||||
|
||||
nix-collect-garbage
|
||||
|
||||
# Check that file still exists.
|
||||
[ "$(cat $(cat $outPath))" = "Hello World!" ]
|
Loading…
Reference in a new issue