This commit is contained in:
mrbesen 2022-10-23 14:05:48 +02:00
parent 7e1e39e592
commit f9df723386
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
3 changed files with 9 additions and 10 deletions

View File

@ -34,7 +34,7 @@ Files& getFiles(uint64_t fs, std::map<uint64_t, Files>& 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::multimap<uint64_t, std::shared_ptr<Fil
// remove all files with a size of 0
files.erase( (const uint64_t& ) 0 );
// remove all files, where they are the only
// remove all files, where they are the only one with that size (there cant be any duplicate so no need to hash them)
for(auto it = files.begin(); it != files.end(); ) {
auto upper = files.upper_bound(it->first);
auto next = ++it;
auto next = it;
++next;
// only one file with this filesize
if(next == upper) {

View File

@ -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<File>(fileSize, inode, linkCount, path);
newfiles.insert({fileSize, file});
newfiles.insert({fileSize, std::make_shared<File>(fileSize, inode, linkCount, path)});
}

View File

@ -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<uint64_t, std::ratio<60>> eta = std::chrono::duration_cast<std::chrono::minutes>((usedtime / (double) pb.currentBytes) * pb.maxBytes);
std::chrono::duration<uint64_t, std::ratio<60>> eta = std::chrono::duration_cast<std::chrono::minutes>((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<std::chrono::seconds>(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;
}