From b2ef41d635d054c1b148baa18afa648d06d5fbdc Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Tue, 17 Dec 2024 17:59:00 -0600 Subject: [PATCH] Further cleanup --- cpp/build-packages.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/cpp/build-packages.cpp b/cpp/build-packages.cpp index 82a5333..6bd5227 100644 --- a/cpp/build-packages.cpp +++ b/cpp/build-packages.cpp @@ -60,10 +60,6 @@ static std::mutex& get_repo_mutex(const fs::path& repo_path) { return repo_mutexes[repo_path]; } -// Mutex and vector to store dput futures -static std::mutex dput_futures_mutex; -static std::vector> dput_futures; - // Mutex and map to store failed packages and their reasons static std::mutex failures_mutex; static std::map failed_packages; @@ -99,18 +95,19 @@ static int worker_count = 5; static bool verbose = false; static std::ofstream log_file_stream; +// Function to get the current UTC time as a formatted string +std::string get_current_utc_time() { + auto now = std::chrono::system_clock::now(); + std::time_t now_c = std::chrono::system_clock::to_time_t(now); + std::tm tm_utc; + gmtime_r(&now_c, &tm_utc); + char buffer[20]; + std::strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%SZ", &tm_utc); + return std::string(buffer); +} + // Function declarations static std::optional run_lintian(const fs::path& source_path); -static void log_all(const std::string &level, const std::string &msg, bool is_error=false); -static void log_info(const std::string &msg); -static void log_warning(const std::string &msg); -static void log_error(const std::string &msg); -static void log_verbose(const std::string &msg); -static void print_help(const std::string &prog_name); -static void run_command_silent_on_success(const std::vector &cmd, const std::optional &cwd = std::nullopt); -static void git_init_once(); -static void git_fetch_and_checkout(const fs::path &repo_path, const std::string &repo_url, const std::optional &branch); -static YAML::Node load_config(const fs::path &config_path); static void publish_lintian(); static std::vector get_exclusions(const fs::path &packaging); static void run_source_lintian(const std::string &name, const fs::path &source_path); @@ -122,7 +119,6 @@ static void build_package_stage(Package &pkg, const YAML::Node &releases); static void build_package_stage_wrapper(Package &pkg, const YAML::Node &releases); static void upload_package_stage(Package &pkg, bool skip_dput); static void run_lintian_stage(Package &pkg); -static void clean_old_logs_local(const fs::path &log_dir); // Removed to avoid ambiguity int main(int argc, char** argv) { std::string prog_name = fs::path(argv[0]).filename().string(); @@ -261,8 +257,7 @@ int main(int argc, char** argv) { log_info("Package pulled successfully."); } catch(std::exception &e) { log_error(std::string("Pull task generated an exception: ") + e.what()); - // Record the failure if not already recorded - // (Handled inside pull_package) + // Failure already recorded inside pull_package } } log_info("Completed Stage 1: All packages pulled."); @@ -369,9 +364,11 @@ SUMMARY: log_info("Skipping cleanup as per flag."); } + // Publish Lintian results log_info("Publishing Lintian results."); publish_lintian(); + // Final Cleanup of old logs log_info("Cleaning old logs."); try { clean_old_logs(LOG_DIR); // Using common::clean_old_logs @@ -693,9 +690,9 @@ static void run_source_lintian(const std::string &name, const fs::path &source_p } log_verbose("Created Lintian suppression file: " + temp_file.string()); std::string cmd = "lintian -EvIL +pedantic --suppress-tags-from-file " + temp_file.string() + " " + source_path.string() + " 2>&1"; - - // Using the unique_ptr with correct deleter to avoid warnings - auto deleter = [](FILE* ptr) { pclose(ptr); }; + + // Using a lambda deleter to ensure the correct signature and avoid warnings + auto deleter = [](FILE* ptr) { if(ptr) pclose(ptr); }; std::unique_ptr pipe(popen(cmd.c_str(), "r"), deleter); if(!pipe) {