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
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()
// 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);
//}
}
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<Patch>(),
+ e = God->pool().byKindEnd<Patch>();
+ for (; it != e; ++it )
+ {
+ Resolvable::constPtr res = it->resolvable();
+ Patch::constPtr patch = asKind<Patch>(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;
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);
}
RpmCallbacks rpm_callbacks;
SourceCallbacks source_callbacks;
MediaCallbacks media_callbacks;
+KeyRingCallbacks keyring_callbacks;
+DigestCallbacks digest_callbacks;
typedef map<string, list<string> > parsed_opts;
alias = arguments[1];
// load gpg keys
- // FIXME only once
- cerr_v << "initializing target" << endl;
- God->initializeTarget("/");
+ cond_init_target ();
try {
// also stores it
return !help;
}
+ cond_init_target ();
try {
// also stores it
rename_source (arguments[0], arguments[1]);
return 1;
}
- KeyRingCallbacks keyring_callbacks;
- DigestCallbacks digest_callbacks;
-
cond_init_system_sources ();
for ( std::list<Url>::const_iterator it = gSettings.additional_sources.begin(); it != gSettings.additional_sources.end(); ++it )
}
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;