From fabe6d901b06edb14f7bf149b5fdc97e88df179d Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Sun, 1 Oct 2006 09:15:27 +0000 Subject: [PATCH] patch-check implemented always initialize all callbacks read gpg keys also for service-rename more messages moved from stdout to verbose stderr --- tools/zmart/zmart-misc.cc | 45 ++++++++++++++++++++++++++++++++++++++++---- tools/zmart/zmart-misc.h | 2 ++ tools/zmart/zmart-sources.cc | 4 ++-- tools/zmart/zypper.cc | 27 ++++++++++++-------------- 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/tools/zmart/zmart-misc.cc b/tools/zmart/zmart-misc.cc index fa53126..46a8586 100644 --- a/tools/zmart/zmart-misc.cc +++ b/tools/zmart/zmart-misc.cc @@ -17,6 +17,16 @@ extern ZYpp::Ptr God; extern RuntimeData gData; extern Settings gSettings; + +void cond_init_target () { + static bool done = false; + if (!done) { + cerr_v << "Initializing Target" << endl; + God->initializeTarget("/"); + done = true; + } +} + // read callback answer // can either be '0\n' -> false // or '1\n' -> true @@ -261,8 +271,10 @@ void cond_load_resolvables () void load_target() { - cout << "Adding system resolvables to pool..." << endl; - God->addResolvables( God->target()->resolvables(), true); + cerr_v << "Adding system resolvables to the pool..." << endl; + ResStore tgt_resolvables(God->target()->resolvables()); + cerr_v << " " << tgt_resolvables.size() << " resolvables." << endl; + God->addResolvables(tgt_resolvables, true /*installed*/); } void load_sources() @@ -273,9 +285,9 @@ void load_sources() // skip non YUM sources for now //if ( it->type() == "YUM" ) //{ - cout << "Adding " << it->alias() << " resolvables to the pool..." << endl; + cerr_v << "Adding " << it->alias() << " resolvables to the pool..." << endl; ResStore src_resolvables(it->resolvables()); - cout << " " << src_resolvables.size() << " resolvables." << endl; + cerr_v << " " << src_resolvables.size() << " resolvables." << endl; God->addResolvables(src_resolvables); //} } @@ -294,6 +306,31 @@ void resolve() God->resolver()->resolvePool(); } +//! are there applicable patches? +void patch_check () +{ + cerr_vv << "patch check" << endl; + gData.patches_count = gData.security_patches_count = 0; + + ResPool::byKind_iterator + it = God->pool().byKindBegin(), + e = God->pool().byKindEnd(); + for (; it != e; ++it ) + { + Resolvable::constPtr res = it->resolvable(); + Patch::constPtr patch = asKind(res); + + if ( it->status().isNeeded() ) + { + gData.patches_count++; + if (patch->category() == "security") + gData.security_patches_count++; + } + } + + cout << gData.patches_count << " patches needed. ( " << gData.security_patches_count << " security patches )" << std::endl; +} + void show_pool() { MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl; diff --git a/tools/zmart/zmart-misc.h b/tools/zmart/zmart-misc.h index a13d520..f063b75 100644 --- a/tools/zmart/zmart-misc.h +++ b/tools/zmart/zmart-misc.h @@ -14,6 +14,7 @@ #include "zypp/Url.h" #include "zypp/ResObject.h" +void cond_init_target (); bool readBoolAnswer(); zypp::ResObject::Kind string_to_kind (const std::string &skind); void mark_for_install( const zypp::ResObject::Kind &kind, @@ -29,6 +30,7 @@ void load_sources(); void establish (); void resolve(); void show_pool(); +void patch_check(); void usage(int argc, char **argv); #endif diff --git a/tools/zmart/zmart-sources.cc b/tools/zmart/zmart-sources.cc index db45ff2..f451f19 100644 --- a/tools/zmart/zmart-sources.cc +++ b/tools/zmart/zmart-sources.cc @@ -38,14 +38,14 @@ void init_system_sources() manager = SourceManager::sourceManager(); try { - cout << "Restoring system sources..." << endl; + cerr_v << "Restoring system sources..." << endl; manager->restore("/"); } catch (Exception & excpt_r) { ZYPP_CAUGHT (excpt_r); ERR << "Couldn't restore sources" << endl; - cout << "Fail to restore sources" << endl; + cerr << "Failed to restore sources" << endl; exit(-1); } diff --git a/tools/zmart/zypper.cc b/tools/zmart/zypper.cc index d10ef2e..27d7a16 100644 --- a/tools/zmart/zypper.cc +++ b/tools/zmart/zypper.cc @@ -38,6 +38,8 @@ ostream no_stream(NULL); RpmCallbacks rpm_callbacks; SourceCallbacks source_callbacks; MediaCallbacks media_callbacks; +KeyRingCallbacks keyring_callbacks; +DigestCallbacks digest_callbacks; typedef map > parsed_opts; @@ -406,9 +408,7 @@ int main(int argc, char **argv) alias = arguments[1]; // load gpg keys - // FIXME only once - cerr_v << "initializing target" << endl; - God->initializeTarget("/"); + cond_init_target (); try { // also stores it @@ -454,6 +454,7 @@ int main(int argc, char **argv) return !help; } + cond_init_target (); try { // also stores it rename_source (arguments[0], arguments[1]); @@ -497,9 +498,6 @@ int main(int argc, char **argv) return 1; } - KeyRingCallbacks keyring_callbacks; - DigestCallbacks digest_callbacks; - cond_init_system_sources (); for ( std::list::const_iterator it = gSettings.additional_sources.begin(); it != gSettings.additional_sources.end(); ++it ) @@ -578,24 +576,23 @@ int main(int argc, char **argv) } if (command == "patch-check" || command == "pchk") { - KeyRingCallbacks keyring_callbacks; - DigestCallbacks digest_callbacks; - + cond_init_target (); cond_init_system_sources (); // TODO additional_sources // TODO warn_no_sources - - // dont add rpms - cerr_v << "initializing target" << endl; - God->initializeTarget("/"); // TODO calc token? // now load resolvables: - cond_load_resolvables (); establish (); - show_pool (); + patch_check (); + + if (gData.security_patches_count > 0) + return 2; + if (gData.patches_count > 0) + return 1; + return 0; } return 0; -- 2.7.4