Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEN-7159: Progress reader updates the output only when progressing #1657

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mender-update/progress_reader/progress_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ expected::ExpectedSize Reader::Read(
if (exp_read) {
bytes_read_ += exp_read.value();
int percentage = (bytes_read_ / static_cast<float>(tot_size_)) * 100;
if (percentage > last_percentage) {
if (percentage > last_percentage_) {
cerr << "\r" << percentage << "%";
last_percentage_ = percentage;
}
}
return exp_read;
Expand Down
2 changes: 1 addition & 1 deletion src/mender-update/progress_reader/progress_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Reader : virtual public io::Reader {
shared_ptr<io::Reader> reader_;
size_t tot_size_;
size_t bytes_read_ {0};
int last_percentage {-1};
int last_percentage_ {-1};
};

} // namespace progress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ TEST(ProgressReaderTests, RegularRead) {

std::string output = testing::internal::GetCapturedStderr();

EXPECT_EQ(output, "\r0%\r5%\r5%\r25%\r90%\r100%");
EXPECT_EQ(output, "\r0%\r5%\r25%\r90%\r100%");
}