diff --git a/src/libutil/posix-source-accessor.cc b/src/libutil/posix-source-accessor.cc index e1eaeb012..b96df39f0 100644 --- a/src/libutil/posix-source-accessor.cc +++ b/src/libutil/posix-source-accessor.cc @@ -33,13 +33,6 @@ 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, @@ -57,8 +50,12 @@ 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"); + if (!S_ISREG(st.st_mode)) { + std::string fileContent = nix::readFile(path.abs()); + sizeCallback(fileContent.size()); + sink(fileContent); + return; + } sizeCallback(st.st_size); diff --git a/src/libutil/posix-source-accessor.hh b/src/libutil/posix-source-accessor.hh index 639fdaaaf..717c8f017 100644 --- a/src/libutil/posix-source-accessor.hh +++ b/src/libutil/posix-source-accessor.hh @@ -25,8 +25,6 @@ struct PosixSourceAccessor : virtual SourceAccessor */ time_t mtime = 0; - std::string readFile(const CanonPath & path) override; - void readFile( const CanonPath & path, Sink & sink,