Simplify Crashdump file transfer
This changes to a streambuf_iterator to read the file contents
into the response body. It may be slightly slower, but it's
easier to read and has less opportunity for errors.
Tested:
Confirmed that a Crashdump file can be successfully downloaded
through Redfish using a browser.
Change-Id: Ic143fe4274678e89330bf354d1b8098550e8b85b
Signed-off-by: Jason M. Bills <jason.m.bills@intel.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 1b84e3b..3877541 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -2846,21 +2846,10 @@
fileName);
return;
}
- std::ifstream ifs(dbusFilepath, std::ios::in |
- std::ios::binary |
- std::ios::ate);
- std::ifstream::pos_type fileSize = ifs.tellg();
- if (fileSize < 0)
- {
- messages::generalError(asyncResp->res);
- return;
- }
- ifs.seekg(0, std::ios::beg);
- std::streamsize streamFileSize =
- static_cast<std::streamsize>(fileSize);
- size_t sFileSize = static_cast<size_t>(fileSize);
- asyncResp->res.body().resize(sFileSize, '\0');
- ifs.read(asyncResp->res.body().data(), streamFileSize);
+ std::ifstream ifs(dbusFilepath,
+ std::ios::in | std::ios::binary);
+ asyncResp->res.body() = std::string(
+ std::istreambuf_iterator<char>{ifs}, {});
// Configure this to be a file download when accessed
// from a browser