summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildtool/file_system/TARGETS1
-rw-r--r--src/buildtool/file_system/file_system_manager.hpp40
2 files changed, 23 insertions, 18 deletions
diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS
index 5b8378d0..a55a900c 100644
--- a/src/buildtool/file_system/TARGETS
+++ b/src/buildtool/file_system/TARGETS
@@ -48,6 +48,7 @@
, ["src/buildtool/logging", "logging"]
, ["src/buildtool/system", "system"]
, ["src/utils/cpp", "expected"]
+ , ["src/utils/cpp", "incremental_reader"]
, ["src/utils/cpp", "path"]
]
, "stage": ["src", "buildtool", "file_system"]
diff --git a/src/buildtool/file_system/file_system_manager.hpp b/src/buildtool/file_system/file_system_manager.hpp
index 47f39ee9..aa151b7a 100644
--- a/src/buildtool/file_system/file_system_manager.hpp
+++ b/src/buildtool/file_system/file_system_manager.hpp
@@ -42,6 +42,7 @@
#include <functional>
#include <optional>
#include <string>
+#include <string_view>
#include <system_error>
#include <unordered_set>
#include <utility>
@@ -55,6 +56,7 @@
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/system/system.hpp"
#include "src/utils/cpp/expected.hpp"
+#include "src/utils/cpp/incremental_reader.hpp"
#include "src/utils/cpp/path.hpp"
namespace detail {
@@ -702,28 +704,30 @@ class FileSystemManager {
file.string());
return std::nullopt;
}
+
+ auto const to_read = IncrementalReader::FromFile(kChunkSize, file);
+ if (not to_read.has_value()) {
+ Logger::Log(LogLevel::Debug,
+ "FileSystemManager: failed to create reader for {}\n{}",
+ file.string(),
+ to_read.error());
+ return std::nullopt;
+ }
+
try {
- std::string chunk{};
std::string content{};
- chunk.resize(kChunkSize);
- std::ifstream file_reader(file.string(), std::ios::binary);
- if (file_reader.is_open()) {
- auto ssize = gsl::narrow<std::streamsize>(chunk.size());
- while (file_reader.good()) {
- file_reader.read(chunk.data(), ssize);
- auto count = file_reader.gcount();
- if (count == ssize) {
- content += chunk;
- }
- else {
- content +=
- chunk.substr(0, gsl::narrow<std::size_t>(count));
- }
+ content.reserve(to_read->GetContentSize());
+ for (auto chunk : *to_read) {
+ if (not chunk.has_value()) {
+ Logger::Log(LogLevel::Error,
+ "reading file failed {}:\n{}",
+ file.string(),
+ chunk.error());
+ return std::nullopt;
}
- file_reader.close();
- return content;
+ content.append(*chunk);
}
- return std::nullopt;
+ return content;
} catch (std::exception const& e) {
Logger::Log(LogLevel::Error,
"reading file {}:\n{}",