20 const auto filepath = std::filesystem::path(file);
21 const auto parent_path = filepath.parent_path();
22 const auto zip_path = parent_path /
"old_logs.zip";
24 struct zip_t* zip =
nullptr;
25 if (std::filesystem::exists(zip_path))
27 zip = zip_open(zip_path.string().c_str(), ZIP_DEFAULT_COMPRESSION_LEVEL,
'a');
31 zip = zip_open(zip_path.string().c_str(), ZIP_DEFAULT_COMPRESSION_LEVEL,
'w');
34 for (
const auto& path : std::filesystem::recursive_directory_iterator(parent_path))
36 const auto entry_path = std::filesystem::path(path);
37 if (std::filesystem::is_regular_file(entry_path) && entry_path.extension() ==
".log" && entry_path.stem() != filepath.stem())
39 zip_entry_open(zip, entry_path.filename().string().c_str());
40 zip_entry_fwrite(zip, entry_path.string().c_str());
43 std::filesystem::remove(entry_path);