From bf58fa94146ca00bd1fb61a06939f856987229ee Mon Sep 17 00:00:00 2001 From: Binbin Date: Thu, 20 Apr 2023 18:03:47 +0800 Subject: [PATCH] changing it to use file.good, thanks PragmaTwice --- src/cluster/cluster.cc | 4 +--- src/config/config.cc | 6 ++---- utils/kvrocks2redis/config.cc | 3 +-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/cluster/cluster.cc b/src/cluster/cluster.cc index 89af7f7c247..724a6045fe9 100644 --- a/src/cluster/cluster.cc +++ b/src/cluster/cluster.cc @@ -613,9 +613,7 @@ Status Cluster::LoadClusterNodes(const std::string &file_path) { int64_t version = -1; std::string id, nodes_info; std::string line; - while (std::getline(file, line)) { - if (file.eof()) break; - + while (file.good() && std::getline(file, line)) { auto parsed = ParseConfigLine(line); if (!parsed) return parsed.ToStatus().Prefixed("malformed line"); if (parsed->first.empty() || parsed->second.empty()) continue; diff --git a/src/config/config.cc b/src/config/config.cc index 77825aea073..f9768e853c1 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -726,8 +726,7 @@ Status Config::Load(const CLIOptions &opts) { std::string line; int line_num = 1; - while (!in->eof()) { - std::getline(*in, line); + while (in.good() && std::getline(*in, line)) { if (auto s = parseConfigFromString(line, line_num); !s.IsOK()) { return s.Prefixed(fmt::format("at line #L{}", line_num)); } @@ -829,8 +828,7 @@ Status Config::Rewrite() { std::ifstream file(path_); if (file.is_open()) { std::string raw_line; - while (std::getline(file, raw_line)) { - if (file.eof()) break; + while (file.good() && std::getline(file, raw_line)) { auto parsed = ParseConfigLine(raw_line); if (!parsed || parsed->first.empty()) { lines.emplace_back(raw_line); diff --git a/utils/kvrocks2redis/config.cc b/utils/kvrocks2redis/config.cc index 6a8974ff01b..907c9495ee1 100644 --- a/utils/kvrocks2redis/config.cc +++ b/utils/kvrocks2redis/config.cc @@ -126,8 +126,7 @@ Status Config::Load(std::string path) { std::string line; int line_num = 1; - while (std::getline(file, line)) { - if (file.eof()) break; + while (file.good() && std::getline(file, line)) { Status s = parseConfigFromString(line); if (!s.IsOK()) { return s.Prefixed(fmt::format("at line #L{}", line_num));