Skip to content

Commit

Permalink
fix progress trailing number bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nshaheed committed Jan 25, 2025
1 parent f044fcc commit fc9960f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion chump-cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ int main(int argc, const char **argv) {
return 0;
}


// if the manifest isn't loading properly, only allow `chump list -u`.
// this is an escape hatch, because failing to parse manifest.json will
// result in an exception and the program won't continue.
Expand Down
10 changes: 7 additions & 3 deletions src/fetch.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <chrono>
#include <filesystem>
#include <iostream>
#include <math.h>
#include <sstream>

#include "fetch.h"
Expand Down Expand Up @@ -31,8 +32,9 @@ int progressCallback(void *clientp, double dltotal, double dlnow,
}
// metadata for the progress bar

// Calculate progress percentage
double progress = (dlnow > 0) ? ((double)dlnow / (double)dltotal) : 0.0;
double progress = 0;
if (dltotal >= 1.0)
progress = (dlnow > 0) ? ((double)dlnow / (double)dltotal) : 0.0;

int bar_width = CHUMP_PROGRESS_BAR_WIDTH; // Width of the progress bar
int filled_width = progress * bar_width;
Expand Down Expand Up @@ -73,7 +75,9 @@ int progressCallback(void *clientp, double dltotal, double dlnow,
else
line += " ";
}
line += string("] ") + std::to_string((int)(progress * 100 + .5)) + "%";

line += string("] ") + std::to_string((int)(progress * 100 + .5)) +
"% ";
std::cerr << "\r" << line.c_str();

return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ std::string hash_file(fs::path filename) {

bool validate_manifest(fs::path manifest_path) {
if (!fs::exists(manifest_path)) {
std::cerr << "[chump]: unable to find package list (manifest.json), fetching..."
<< std::endl;
std::cerr
<< "[chump]: unable to find package list (manifest.json), fetching..."
<< std::endl;
return false;
}

Expand Down Expand Up @@ -231,7 +232,6 @@ bool unzipFile(const std::string &zipPath, const std::string &outputDir) {
if (filename[strlen(filename) - 1] == '/') {
std::filesystem::create_directories(fullPath);
} else {
std::cerr << "[chump]: installing \"" << fullPath << "\"" << std::endl;
// Extract file
unzOpenCurrentFile(zipFile);

Expand Down

0 comments on commit fc9960f

Please sign in to comment.