diff --git a/tools/zypp-runpurge.cc b/tools/zypp-runpurge.cc index a77c547d1..546e54f53 100644 --- a/tools/zypp-runpurge.cc +++ b/tools/zypp-runpurge.cc @@ -34,7 +34,7 @@ int main ( int argc, char *argv[] ) auto result = options.parse( argc, argv ); - if ( result.count( "help" ) || !result.count("uname") || !result.positionals().size() ) + if ( result.count( "help" ) || !result.positionals().size() ) return usage( options, 1 ); const std::string &testcaseDir = result.positionals().front(); @@ -58,24 +58,48 @@ int main ( int argc, char *argv[] ) return 1; } + std::string unameR; + if ( result.count("uname") ) { + unameR = result["uname"].arg(); + } else { + std::cout << "No --uname provided. Guessing it from the latest kernel-default installed...." << std::endl; + const PoolItem & running( ui::Selectable::get("kernel-default")->theObj() ); + if ( not running ) { + std::cerr << "Oops: No installed kernel-default." << std::endl; + return usage( options, 1 ); + } + std::cout << "Guess running: " << running.asString() << endl; + const Capability unameRProvides { "kernel-uname-r" }; // indicator provides + for ( const auto & cap : running.provides() ) { + if ( cap.matches( unameRProvides ) == CapMatch::yes ) { + unameR = cap.detail().ed().asString(); + break; + } + } + if ( unameR.empty() ) { + std::cerr << "Oops: Guessed kernel does not provide " << unameRProvides << std::endl; + return usage( options, 1 ); + } + std::cout << "Guess --uname: " << unameR << endl; + } + std::string keepSpec = "oldest,running,latest"; if ( result.count("keepSpec") ) { keepSpec = result["keepSpec"].arg(); } + PurgeKernels krnls; - krnls.setUnameR( result["uname"].arg() ); + krnls.setUnameR( unameR ); krnls.setKeepSpec( keepSpec ); krnls.markObsoleteKernels(); - const auto &makeNVRA = []( const PoolItem &pck ) -> std::string { - return pck.name() + "-" + pck.edition().asString() + "." + pck.arch().asString(); - }; + std::cout << "Purged kernels: " << std::endl; auto pool = ResPool::instance(); const filter::ByStatus toBeUninstalledFilter( &ResStatus::isToBeUninstalled ); for ( auto it = pool.byStatusBegin( toBeUninstalledFilter ); it != pool.byStatusEnd( toBeUninstalledFilter ); it++ ) { - std::cout << "Removing " << makeNVRA(*it) + (it->status().isByUser() ? " (by user)" : " (autoremoved)") << std::endl; + std::cout << "Removing " << it->asString() + (it->status().isByUser() ? " (by user)" : " (autoremoved)") << std::endl; } return 0;