mirror of
https://github.com/NixOS/nix.git
synced 2024-11-25 00:02:25 +00:00
fix builtins.readFile
for non regular files like /dev/stdin
This commit is contained in:
parent
6fd350241c
commit
ffcd87fb2b
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user