// Give every stored file an expiry. // // A file's TTL could only be set at upload before 2.8, so everything written // before that is immortal - and FileRecord carries no expiry field, so a file // that already has one cannot be told from a file that does not. The only // available move is to set one on all of them. // // 90 days: these are working data - source photos, generated images, downloads - // all of it either regenerable or already published elsewhere. Long enough that // nothing in flight is lost, short enough that the store does not grow for ever. #include #include #include using namespace smartbotic::database; int main(int argc, char** argv) { const uint32_t ttl = (argc > 1) ? (uint32_t)atoi(argv[1]) : 90u*24*3600; Client::Config cfg; cfg.address="192.168.2.150:9004"; cfg.project="smartbotic-automation"; Client c(cfg); if (!c.connect()) return 1; std::set seen; int set_ok=0, failed=0; for (uint32_t off=0; off<5000; off+=100) { auto page = c.listFiles("", "", 100, off); if (page.files.empty()) break; for (auto& f : page.files) { if (!seen.insert(f.id).second) continue; if (c.setFileTtl(f.id, ttl)) set_ok++; else failed++; } if (page.files.size() < 100) break; } printf("files seen %zu, expiry set on %d, failed %d (ttl %u s = %.0f days)\n", seen.size(), set_ok, failed, ttl, ttl/86400.0); return failed ? 1 : 0; }