Browse Source

Not traking entries, but rather tracking paths

main
Unbewohnte 3 years ago
parent
commit
21d4610dc6
  1. 1
      .gitignore
  2. 24
      src/broom.cpp
  3. 6
      src/broom.hpp

1
.gitignore vendored

@ -1,4 +1,5 @@
bin/broom bin/broom
bin/broom_old
build/CMakeFiles/ build/CMakeFiles/
build/cmake_install.cmake build/cmake_install.cmake
build/CMakeCache.txt build/CMakeCache.txt

24
src/broom.cpp

@ -54,8 +54,7 @@ void Broom::track(const std::filesystem::path dir) {
continue; continue;
}; };
Entry entry(dir_entry.path()); m_tracked_filepaths.push_back(dir_entry);
m_tracked_entries.push_back(entry);
}; };
if (m_benchmarking) { if (m_benchmarking) {
@ -74,14 +73,15 @@ uintmax_t Broom::untrack_unique_sizes() {
// key: size, value: amount of occurences // key: size, value: amount of occurences
std::map<uintmax_t, uintmax_t> sizes_map; std::map<uintmax_t, uintmax_t> sizes_map;
for (Entry entry : m_tracked_entries) { for (std::filesystem::path filepath : m_tracked_filepaths) {
// check if size of this entry is already in the map // check if size of this entry is already in the map
// if yes --> increment occurences counter // if yes --> increment occurences counter
// if not --> add it to the map with a counter of 1 // if not --> add it to the map with a counter of 1
auto iterator = sizes_map.find(entry.filesize); uintmax_t filesize = std::filesystem::file_size(filepath);
auto iterator = sizes_map.find(filesize);
if (iterator == sizes_map.end()) { if (iterator == sizes_map.end()) {
// there is no such size // there is no such size
sizes_map.insert({entry.filesize, 1}); sizes_map.insert({filesize, 1});
} else { } else {
// there is such size // there is such size
sizes_map[iterator->first]++; sizes_map[iterator->first]++;
@ -89,8 +89,9 @@ uintmax_t Broom::untrack_unique_sizes() {
}; };
uintmax_t untracked = 0; uintmax_t untracked = 0;
std::remove_if(m_tracked_entries.begin(), m_tracked_entries.end(), [&untracked, sizes_map](Entry entry) -> bool{ m_tracked_filepaths.erase(std::remove_if(m_tracked_filepaths.begin(), m_tracked_filepaths.end(), [&untracked, sizes_map](std::filesystem::path filepath) -> bool{
auto iter = sizes_map.find(entry.filesize); uintmax_t filesize = std::filesystem::file_size(filepath);
auto iter = sizes_map.find(filesize);
if (iter->second == 1) { if (iter->second == 1) {
// unique // unique
untracked++; untracked++;
@ -100,7 +101,8 @@ uintmax_t Broom::untrack_unique_sizes() {
// std::cout << "duplicate fsize: " << iter->first << " occurences: " << iter->second << std::endl; // std::cout << "duplicate fsize: " << iter->first << " occurences: " << iter->second << std::endl;
return false; return false;
}); }));
return untracked; return untracked;
}; };
@ -112,7 +114,7 @@ uintmax_t Broom::untrack_unique_sizes() {
// std::map<char[CHECKSUM_SIZE], uintmax_t> contents_map; // std::map<char[CHECKSUM_SIZE], uintmax_t> contents_map;
// std::map<char[CHECKSUM_SIZE], uintmax_t>::iterator iterator; // std::map<char[CHECKSUM_SIZE], uintmax_t>::iterator iterator;
// //
// for (Entry& entry : m_tracked_entries) { // for (Entry& entry : m_tracked_filepaths) {
// // the same logic: // // the same logic:
// // check if contents of this entry is already in the map // // check if contents of this entry is already in the map
// // if yes --> increment occurences counter // // if yes --> increment occurences counter
@ -136,7 +138,7 @@ uintmax_t Broom::untrack_unique_sizes() {
// // not a unique size. Keep such entries // // not a unique size. Keep such entries
// } else { // } else {
// // a unique one. Untrack such an entry // // a unique one. Untrack such an entry
// std::remove_if(m_tracked_entries.begin(), m_tracked_entries.end(), [contents_entry](Entry e) -> bool { // std::remove_if(m_tracked_filepaths.begin(), m_tracked_filepaths.end(), [contents_entry](Entry e) -> bool {
// return (e.compare_checksums(contents_entry.first)); // return (e.compare_checksums(contents_entry.first));
// }); // });
// untracked++; // untracked++;
@ -163,7 +165,7 @@ void Broom::find_duplicates() {
<< std::endl; << std::endl;
} else { } else {
size_t startsize = m_tracked_entries.size(); size_t startsize = m_tracked_filepaths.size();
std::cout << "Tracking " << startsize << std::endl; std::cout << "Tracking " << startsize << std::endl;
uintmax_t global_untracked = 0; uintmax_t global_untracked = 0;

6
src/broom.hpp

@ -41,8 +41,8 @@ protected:
uintmax_t m_sweeped_files; uintmax_t m_sweeped_files;
// how many bytes was (would be ?) freed // how many bytes was (would be ?) freed
uintmax_t m_sweeped_size; uintmax_t m_sweeped_size;
// entries that possibly contain duplicates // paths to tracked files
std::vector<Entry> m_tracked_entries; std::vector<std::filesystem::path> m_tracked_filepaths;
public: public:
Broom(Options options); Broom(Options options);
@ -51,7 +51,7 @@ public:
// Print current statistics // Print current statistics
void print_statistics(); void print_statistics();
// get all entities from path recursively and track them // recursively track every file that lies in given path
void track(const std::filesystem::path path); void track(const std::filesystem::path path);
// find all duplicates in the directory // find all duplicates in the directory

Loading…
Cancel
Save