Skip to content

Commit

Permalink
changing it to use file.good, thanks PragmaTwice
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-binbin committed Apr 20, 2023
1 parent 8daaf6a commit bf58fa9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/cluster/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions utils/kvrocks2redis/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit bf58fa9

Please sign in to comment.