diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-05-06 12:01:40 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-05-06 12:01:40 +0200 |
commit | 2f8ee4578f0784411a2b14620d598f0d1d604122 (patch) | |
tree | e6ec8def584ce57ebf41f927e0f66d3c4ecb715a /src/libutil | |
parent | 6f3244ce4517cc51ef3ffd39025152aa7046ef69 (diff) | |
parent | 74a1bfdcab03d3c6ecb9353f4bae0a0c550ddb98 (diff) |
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/logging.cc | 10 | ||||
-rw-r--r-- | src/libutil/serialise.hh | 3 | ||||
-rw-r--r-- | src/libutil/util.cc | 13 | ||||
-rw-r--r-- | src/libutil/util.hh | 4 |
4 files changed, 10 insertions, 20 deletions
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index 777650de5..3cc4ef8f1 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -63,16 +63,6 @@ public: writeToStderr(prefix + filterANSIEscapes(fs.s, !tty) + "\n"); } - void result(ActivityId act, ResultType type, const std::vector<Field> & fields) override - { - if (type == resBuildLogLine || type == resPostBuildLogLine) { - assert(0 < fields.size()); - assert(fields[0].type == Logger::Field::tString); - auto lastLine = fields[0].s; - log(lvlInfo, lastLine); - } - } - void startActivity(ActivityId act, Verbosity lvl, ActivityType type, const std::string & s, const Fields & fields, ActivityId parent) override diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh index 5780c93a6..a04118512 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/serialise.hh @@ -148,6 +148,9 @@ struct StringSink : Sink { ref<std::string> s; StringSink() : s(make_ref<std::string>()) { }; + explicit StringSink(const size_t reservedSize) : s(make_ref<std::string>()) { + s->reserve(reservedSize); + }; StringSink(ref<std::string> s) : s(s) { }; void operator () (const unsigned char * data, size_t len) override; }; diff --git a/src/libutil/util.cc b/src/libutil/util.cc index aa695e174..4c8e2b26d 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -317,19 +317,16 @@ string readFile(int fd) if (fstat(fd, &st) == -1) throw SysError("statting file"); - std::vector<unsigned char> buf(st.st_size); - readFull(fd, buf.data(), st.st_size); - - return string((char *) buf.data(), st.st_size); + return drainFD(fd, true, st.st_size); } -string readFile(const Path & path, bool drain) +string readFile(const Path & path) { AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC); if (!fd) throw SysError(format("opening file '%1%'") % path); - return drain ? drainFD(fd.get()) : readFile(fd.get()); + return readFile(fd.get()); } @@ -676,9 +673,9 @@ void writeFull(int fd, const string & s, bool allowInterrupts) } -string drainFD(int fd, bool block) +string drainFD(int fd, bool block, const size_t reserveSize) { - StringSink sink; + StringSink sink(reserveSize); drainFD(fd, sink, block); return std::move(*sink.s); } diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 7a846c131..4be1d4580 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -105,7 +105,7 @@ unsigned char getFileType(const Path & path); /* Read the contents of a file into a string. */ string readFile(int fd); -string readFile(const Path & path, bool drain = false); +string readFile(const Path & path); void readFile(const Path & path, Sink & sink); /* Write a string to a file. */ @@ -166,7 +166,7 @@ MakeError(EndOfFile, Error); /* Read a file descriptor until EOF occurs. */ -string drainFD(int fd, bool block = true); +string drainFD(int fd, bool block = true, const size_t reserveSize=0); void drainFD(int fd, Sink & sink, bool block = true); |