This commit is contained in:
King_DuckZ 2021-03-26 21:08:54 +01:00
parent 2a9780bf15
commit 49f2c3d4cb

View file

@ -63,26 +63,6 @@ struct Node {
typedef std::unordered_map<std::string, NotebookInfo> NotebookMapType;
std::ostream& operator<< (std::ostream& str, const NotebookMapType::value_type& v) {
auto& key = v.first;
auto& val = v.second;
str << key << " (\"" << val.visible_name << "\", " << val.type <<
"): deleted=" << std::boolalpha << val.deleted <<
", parent=\"" << val.parent <<
"\", version=" << val.version <<
", files=";
std::string_view sep("");
for (const auto& f : val.files) {
str << sep << f;
sep = ";";
}
str << ", size=" << std::setprecision(2) <<
static_cast<double>(val.total_size) / (1024.0 * 1024.0) << "MiB";
return str;
}
template <typename T>
std::vector<T>& operator+= (std::vector<T>& dst, const std::vector<T>& src) {
dst.insert(dst.end(), src.begin(), src.end());
@ -219,61 +199,13 @@ int main() {
using std::string_view;
auto notebooks = build_notebook_infos(BASE_PATH);
//naive linear delete
//std::uintmax_t total = 0;
//std::uintmax_t freed = 0;
//std::set<std::string_view> dele_list;
//for (auto& nb : notebooks) {
// if (nb.second.deleted) {
// dele_list.insert(nb.first);
// for (const auto& file : nb.second.files) {
// std::cout << BASE_PATH << file << '\n';
// }
// freed += nb.second.total_size;
// }
// total += nb.second.total_size;
//}
//for (auto& nb : notebooks) {
// if (dele_list.count(nb.second.parent) and not nb.second.deleted) {
// std::cerr << "Warning: " << nb.second.parent << " deleted but it's the parent of " << nb.first << "!\n";
// }
//}
//
//std::cout << "Found " << notebooks.size() << " notebooks\n";
//std::cout << "Total size " << std::setprecision(2) <<
// static_cast<double>(total) / (1024.0 * 1024.0 * 1024.0) << "GiB\n";
//std::cout << "Would delete " << dele_list.size() << " notebooks\n";
//std::cout << "Would free " << std::setprecision(2) <<
// static_cast<double>(freed) / (1024.0 * 1024.0 * 1024.0) << "GiB\n";
std::vector<Node> roots = to_tree(notebooks);
//std::cout << "Found " << notebooks.size() << " notebooks\n";
//std::cout << "Collection has " << roots.size() << " roots\n";
//std::cout << " ---------\n";
//for (const auto& root : roots) {
// std::cout << "\tTree \"" << root.name << "\" has " << root.children.size() << " nodes\n\n";
//}
//std::uintmax_t total_mem1 = 0;
std::vector<const NotebookInfo*> dele_list;
for (const auto& root : roots) {
//std::string_view desc;
//if (root.name == "trash")
// desc = "rubbish bin";
//else if (root.name == "")
// desc = "root";
//print_tree(root, desc);
//total_mem1 += recursive_size(root);
for (const auto& root : roots) {
dele_list += make_dele_list(root);
}
//std::cout << "Total size 1: " << total_mem1 << " bytes\n";
//const std::uintmax_t total_mem2 = std::accumulate(notebooks.cbegin(), notebooks.cend(), std::uintmax_t{}, [](std::uintmax_t a, const auto& b) {return a + b.second.total_size;});
//std::cout << "Total size 2: " << total_mem2 << " bytes\n";
for (const NotebookInfo* nb : dele_list) {
for (const auto& f : nb->files) {
std::cout << "/home/root/.local/share/remarkable/xochitl/" << f << '\n';