Compare commits

...

3 Commits

Author SHA1 Message Date
Théophane Hufschmitt
590e87e14d readFile: Only read the full file if it's a non-regular one
Make `SourceAccessor::readFile` stream when reading a regular file, and
only fallback to a non-streaming version otherwise.
2024-02-16 09:23:06 +01:00
ThinkChaos
ffcd87fb2b fix builtins.readFile for non regular files like /dev/stdin 2024-02-14 20:34:50 -05:00
ThinkChaos
6fd350241c tmp: test for readfile stdin 2024-02-14 20:34:50 -05:00
3 changed files with 11 additions and 0 deletions

View File

@@ -50,6 +50,13 @@ void PosixSourceAccessor::readFile(
if (fstat(fd.get(), &st) == -1)
throw SysError("statting file");
if (!S_ISREG(st.st_mode)) {
std::string fileContent = nix::readFile(path.abs());
sizeCallback(fileContent.size());
sink(fileContent);
return;
}
sizeCallback(st.st_size);
off_t left = st.st_size;

View File

@@ -60,6 +60,7 @@ nix_tests = \
fetchGitVerification.sh \
flakes/search-root.sh \
readfile-context.sh \
readfile-stdin.sh \
nix-channel.sh \
recursive.sh \
dependencies.sh \

View File

@@ -0,0 +1,3 @@
source common.sh
[[ $(echo yay | nix eval --raw --impure --expr 'builtins.readFile "/dev/stdin"') = yay ]]