#include "cleanup_plan.h" #include #include "storage_paths.h" namespace roro { namespace { int maxAgeDays(CleanupAge age) { switch (age) { case CleanupAge::OneMonth: return 30; case CleanupAge::ThreeMonths: return 91; case CleanupAge::SixMonths: return 182; case CleanupAge::OneYear: return 365; default: return -1; } } } // namespace CleanupPlan CleanupPlan::make(const std::vector& files, CleanupAge age, int todayDay) { CleanupPlan plan; for (auto& f : files) { if (f.path.rfind("/notes", 0) == 0) continue; // Notes are never cleaned up bool selected = age == CleanupAge::Everything; if (!selected) { size_t slash = f.path.find_last_of('/'); int day = storage::fileDay(slash == std::string::npos ? f.path : f.path.substr(slash + 1)); selected = day >= 0 && todayDay - day > maxAgeDays(age); } if (selected) { plan.paths.push_back(f.path); plan.bytes += f.bytes; } } return plan; } std::string formatBytes(uint64_t bytes) { const char* units[] = {"B", "KB", "MB", "GB"}; double v = static_cast(bytes); int u = 0; while (v >= 1024 && u < 3) { v /= 1024; u++; } char buf[16]; if (u == 0 || v >= 10) std::snprintf(buf, sizeof(buf), "%.0f %s", v, units[u]); else std::snprintf(buf, sizeof(buf), "%.1f %s", v, units[u]); return buf; } } // namespace roro