fix builtins.readFile for non regular files like /dev/stdin

This commit is contained in:
ThinkChaos 2024-02-14 20:34:23 -05:00
parent 6fd350241c
commit ffcd87fb2b
No known key found for this signature in database
3 changed files with 13 additions and 0 deletions

View File

@ -33,6 +33,13 @@ std::filesystem::path PosixSourceAccessor::makeAbsPath(const CanonPath & path)
: root / path.rel();
}
std::string PosixSourceAccessor::readFile(const CanonPath & path)
{
// Can't be implemented as a wrapper of the `Sink` based overload
// since this needs to support non-regular files (like `/dev/stdin`).
return nix::readFile(path.abs());
}
void PosixSourceAccessor::readFile(
const CanonPath & path,
Sink & sink,
@ -50,6 +57,9 @@ void PosixSourceAccessor::readFile(
if (fstat(fd.get(), &st) == -1)
throw SysError("statting file");
// logger->cout("%s %d", path.c_str(), st.st_size);
assert(S_ISREG(st.st_mode) && "sinks are only compatible with regular files since they need to know the size in advance");
sizeCallback(st.st_size);
off_t left = st.st_size;

View File

@ -25,6 +25,8 @@ struct PosixSourceAccessor : virtual SourceAccessor
*/
time_t mtime = 0;
std::string readFile(const CanonPath & path) override;
void readFile(
const CanonPath & path,
Sink & sink,

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 \