diff --git a/src/dedup.cpp b/src/dedup.cpp index af490b4..7c429d1 100644 --- a/src/dedup.cpp +++ b/src/dedup.cpp @@ -34,7 +34,7 @@ Files& getFiles(uint64_t fs, std::map& m) { void Dedup::start() { FileIndexer::map_t foundfiles; for(const SearchFolder& sf : folders) { - foundfiles = indexer.index(sf); + foundfiles.merge(indexer.index(sf)); } uint64_t accFileSize = std::accumulate(foundfiles.begin(), foundfiles.end(), 0ul, [](uint64_t val, auto r){ return val + r.second->filesize; }); @@ -61,10 +61,11 @@ void Dedup::removeUninterestingFiles(std::multimapfirst); - auto next = ++it; + auto next = it; + ++next; // only one file with this filesize if(next == upper) { diff --git a/src/fileindexer.cpp b/src/fileindexer.cpp index f5d8bdb..cce6092 100644 --- a/src/fileindexer.cpp +++ b/src/fileindexer.cpp @@ -81,6 +81,5 @@ void FileIndexer::handleNewFile(ino_t inode, const std::string& path, map_t& new knownInodes.insert(inode); - auto file = std::make_shared(fileSize, inode, linkCount, path); - newfiles.insert({fileSize, file}); + newfiles.insert({fileSize, std::make_shared(fileSize, inode, linkCount, path)}); } diff --git a/src/progressbar.cpp b/src/progressbar.cpp index 2a6c953..85a7df9 100644 --- a/src/progressbar.cpp +++ b/src/progressbar.cpp @@ -23,12 +23,11 @@ std::ostream& operator<<(std::ostream& str, const ProgressBar& pb) { double progress = (pb.currentBytes / (double) pb.maxBytes); auto usedtime = pb.getDuration(); - std::chrono::duration> eta = std::chrono::duration_cast((usedtime / (double) pb.currentBytes) * pb.maxBytes); + std::chrono::duration> eta = std::chrono::duration_cast((usedtime / (double) pb.currentBytes) * (pb.maxBytes - pb.currentBytes) ); // speed - double speed = (pb.currentBytes / (double) usedtime.count()); // B/ms - speed /= 1000; // B/s - uint64_t bytespersecond = (int) speed; // floor + uint64_t usedtimes = std::chrono::duration_cast(usedtime).count(); + uint64_t speed = (usedtimes != 0) ? (pb.currentBytes / usedtimes) : 0; // B/s // generate bar str << "\r["; @@ -44,7 +43,7 @@ std::ostream& operator<<(std::ostream& str, const ProgressBar& pb) { str << "] " << std::setprecision(2) << std::setfill('0') << std::fixed << std::setw(5) << (progress * 100) << "% " << std::setprecision(6) << std::defaultfloat << FileSize(pb.currentBytes) << '/' << FileSize(pb.maxBytes) << " " << pb.currentFiles << '/' << pb.maxFiles << " Files " - << FileSize(bytespersecond) << "/s ETA: " << eta.count() << "s " << std::flush; + << FileSize(speed) << "/s ETA: " << eta.count() << "min " << std::flush; return str; }