Author: visnov
Date: Fri Feb 15 14:20:26 2008
New Revision: 8721
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8721&view=rev
Log:
implemented 'zypper clean'
Modified:
trunk/zypper/doc/zypper-rug
trunk/zypper/doc/zypper.8
trunk/zypper/package/zypper.changes
trunk/zypper/src/zypper-command.cc
trunk/zypper/src/zypper-command.h
trunk/zypper/src/zypper-repos.cc
trunk/zypper/src/zypper-repos.h
trunk/zypper/src/zypper.cc
Modified: trunk/zypper/doc/zypper-rug
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/doc/zypper-rug?rev=8721&r1=8720&r2=8721&view=diff
==============================================================================
--- trunk/zypper/doc/zypper-rug (original)
+++ trunk/zypper/doc/zypper-rug Fri Feb 15 14:20:26 2008
@@ -96,7 +96,7 @@
? service-types (st) List the available service types
System:
- ? clean-cache (cc) Clean the HTTP cache
+ ++ clean-cache (cc) Clean the HTTP cache
N1 load-modules (lm) Load ZMD modules
N1 ping Ping the deamon
N1 restart Restart the daemon
Modified: trunk/zypper/doc/zypper.8
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/doc/zypper.8?rev=8721&r1=8720&r2=8721&view=diff
==============================================================================
--- trunk/zypper/doc/zypper.8 (original)
+++ trunk/zypper/doc/zypper.8 Fri Feb 15 14:20:26 2008
@@ -405,6 +405,16 @@
.I \-D, \-\-download\-only
Only download the raw metadata, don't parse it or build the database.
+.TP
+.B clean ...
+Clean up the local caches for all known repository caches. By default, only downloaded package caches are cleaned.
+.TP
+.I \-m, \-\-metadata
+Clean up repository metadata cache instead of package cache.
+.TP
+.I \-a, \-\-all
+Clean up both repository metadata and package caches.
+
.SH "GLOBAL OPTIONS"
.TP
@@ -716,6 +726,8 @@
Duncan Mac-Vicar
.br
Jan Kupec
+.br
+Stanislav Visnovsky
.SH "SEE ALSO"
.LP
Modified: trunk/zypper/package/zypper.changes
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/package/zypper.changes?rev=8721&r1=8720&r2=8721&view=diff
==============================================================================
--- trunk/zypper/package/zypper.changes (original)
+++ trunk/zypper/package/zypper.changes Fri Feb 15 14:20:26 2008
@@ -1,4 +1,9 @@
-------------------------------------------------------------------
+Fri Feb 15 14:19:01 CET 2008 - visnov@suse.de
+
+- implemented clean command
+
+-------------------------------------------------------------------
Wed Feb 13 11:26:01 CET 2008 - coolo@suse.de
- increase version number to mark satsolver branch
Modified: trunk/zypper/src/zypper-command.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-command.cc?rev=8721&r1=8720&r2=8721&view=diff
==============================================================================
--- trunk/zypper/src/zypper-command.cc (original)
+++ trunk/zypper/src/zypper-command.cc Fri Feb 15 14:20:26 2008
@@ -22,6 +22,7 @@
const ZypperCommand ZypperCommand::MODIFY_REPO(ZypperCommand::MODIFY_REPO_e);
const ZypperCommand ZypperCommand::LIST_REPOS(ZypperCommand::LIST_REPOS_e);
const ZypperCommand ZypperCommand::REFRESH(ZypperCommand::REFRESH_e);
+const ZypperCommand ZypperCommand::CLEAN(ZypperCommand::CLEAN_e);
const ZypperCommand ZypperCommand::INSTALL(ZypperCommand::INSTALL_e);
const ZypperCommand ZypperCommand::REMOVE(ZypperCommand::REMOVE_e);
@@ -47,7 +48,6 @@
const ZypperCommand ZypperCommand::RUG_PATTERN_INFO(ZypperCommand::RUG_PATTERN_INFO_e);
const ZypperCommand ZypperCommand::RUG_PRODUCT_INFO(ZypperCommand::RUG_PRODUCT_INFO_e);
-
ZypperCommand::ZypperCommand(const std::string & strval_r)
: _command(parse(strval_r))
{}
@@ -63,6 +63,7 @@
_table["modifyrepo"]= _table["mr"] = _table["service-modify"] = _table["sm"] = ZypperCommand::MODIFY_REPO_e;
_table["repos"] = _table["lr"] = _table["service-list"] = _table["sl"] = ZypperCommand::LIST_REPOS_e;
_table["refresh"] = _table["ref"] = ZypperCommand::REFRESH_e;
+ _table["clean"] = ZypperCommand::CLEAN_e;
_table["install"] = _table["in"] = ZypperCommand::INSTALL_e;
_table["remove"] = _table["rm"] = ZypperCommand::REMOVE_e;
Modified: trunk/zypper/src/zypper-command.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-command.h?rev=8721&r1=8720&r2=8721&view=diff
==============================================================================
--- trunk/zypper/src/zypper-command.h (original)
+++ trunk/zypper/src/zypper-command.h Fri Feb 15 14:20:26 2008
@@ -16,6 +16,7 @@
static const ZypperCommand MODIFY_REPO;
static const ZypperCommand LIST_REPOS;
static const ZypperCommand REFRESH;
+ static const ZypperCommand CLEAN;
static const ZypperCommand INSTALL;
static const ZypperCommand REMOVE;
@@ -53,6 +54,7 @@
MODIFY_REPO_e,
LIST_REPOS_e,
REFRESH_e,
+ CLEAN_e,
INSTALL_e,
REMOVE_e,
Modified: trunk/zypper/src/zypper-repos.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-repos.cc?rev=8721&r1=8720&r2=8721&view=diff
==============================================================================
--- trunk/zypper/src/zypper-repos.cc (original)
+++ trunk/zypper/src/zypper-repos.cc Fri Feb 15 14:20:26 2008
@@ -800,6 +800,134 @@
// ----------------------------------------------------------------------------
+void clean_repos(Zypper & zypper)
+{
+ RepoManager manager(zypper.globalOpts().rm_options);
+
+ list<RepoInfo> repos;
+ try
+ {
+ repos = manager.knownRepositories();
+ }
+ catch ( const Exception &e )
+ {
+ ZYPP_CAUGHT(e);
+ report_problem(e,
+ _("Error reading repositories:"));
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+
+ // get the list of repos specified on the command line ...
+ list<RepoInfo> specified;
+ list<string> not_found;
+ // ...as command arguments
+ get_repos(zypper, zypper.arguments().begin(), zypper.arguments().end(),
+ specified, not_found);
+ // ...as --repo options
+ parsed_opts::const_iterator tmp1;
+ if ((tmp1 = copts.find("repo")) != copts.end())
+ get_repos(zypper, tmp1->second.begin(), tmp1->second.end(), specified, not_found);
+ report_unknown_repos(not_found);
+
+ cout_v << _("Specified repositories: ");
+ for (list<RepoInfo>::const_iterator it = specified.begin();
+ it != specified.end(); ++it)
+ cout_v << it->alias() << " ";
+ cout_v << endl;
+
+ // should we clean packages or metadata ?
+ bool clean_metadata = (copts.find("metadata") != copts.end());
+ bool clean_packages = (copts.find("metadata") == copts.end());
+
+ if( copts.find("all") != copts.end() )
+ {
+ clean_metadata = true;
+ clean_packages = true;
+ }
+
+ cout_vv << "Metadata will be cleaned: " << clean_metadata << endl;
+ cout_vv << "Packages will be cleaned: " << clean_packages << endl;
+
+ unsigned error_count = 0;
+ unsigned enabled_repo_count = repos.size();
+
+ if (!specified.empty() || not_found.empty())
+ {
+ for (std::list<RepoInfo>::iterator it = repos.begin();
+ it != repos.end(); ++it)
+ {
+ RepoInfo repo(*it);
+
+ if (!specified.empty())
+ {
+ bool found = false;
+ for (list<RepoInfo>::const_iterator it = specified.begin();
+ it != specified.end(); ++it)
+ if (it->alias() == repo.alias())
+ {
+ found = true;
+ break;
+ }
+
+ if (!found)
+ {
+ DBG << repo.alias() << "(#" << ") not specified,"
+ << " skipping." << endl;
+ enabled_repo_count--;
+ continue;
+ }
+ }
+
+ bool error = false;
+ try {
+ if( clean_metadata )
+ {
+ cout_v << "Cleaning metadata for '" << repo.alias () << "'" << endl;
+ manager.cleanMetadata(repo);
+ }
+ if( clean_packages )
+ {
+ cout_v << "Cleaning packages for '" << repo.alias () << "'" << endl;
+ manager.cleanPackages(repo);
+ }
+ } catch(...) {
+ error = true;
+ }
+
+ if (error)
+ {
+ cerr << format(_("Skipping repository '%s' because of the above error."))
+ % repo.name() << endl;
+ ERR << format("Skipping repository '%s' because of the above error.")
+ % repo.name() << endl;
+ error_count++;
+ }
+ }
+ }
+ else
+ enabled_repo_count = 0;
+
+ if (error_count == enabled_repo_count)
+ {
+ cerr << _("Could not clean the repositories because of errors.") << endl;
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+ else if (error_count)
+ {
+ cerr << _("Some of the repositories have not been cleaned up because of an error.") << endl;
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+ else if (!specified.empty())
+ cout << _("Specified repositories have been cleaned up.") << endl;
+ else
+ cout << _("All repositories have been cleaned up.") << endl;
+}
+
+// ----------------------------------------------------------------------------
+
static
std::string timestamp ()
{
Modified: trunk/zypper/src/zypper-repos.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-repos.h?rev=8721&r1=8720&r2=8721&view=diff
==============================================================================
--- trunk/zypper/src/zypper-repos.h (original)
+++ trunk/zypper/src/zypper-repos.h Fri Feb 15 14:20:26 2008
@@ -29,6 +29,12 @@
/**
+ * Clean caches for all repositories.
+ */
+void clean_repos(Zypper & zypper);
+
+
+/**
* Add repository specified by \url to system repositories.
*
* \param url Valid URL of the repository.
@@ -86,7 +92,6 @@
*/
void modify_repo(Zypper & zypper, const std::string & alias);
-
/**
* Load both repository and target resolvables.
*
Modified: trunk/zypper/src/zypper.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=8721&r1=8720&r2=8721&view=diff
==============================================================================
--- trunk/zypper/src/zypper.cc (original)
+++ trunk/zypper/src/zypper.cc Fri Feb 15 14:20:26 2008
@@ -171,6 +171,7 @@
"\tinfo, if\t\tShow full information for packages\n"
"\tpatch-info\t\tShow full information for patches\n"
"\tsource-install, si\tInstall a source package\n"
+ "\tclean\t\t\tClean local caches\n"
"");
static string help_usage = _(
@@ -443,7 +444,8 @@
command() == ZypperCommand::REMOVE_REPO ||
command() == ZypperCommand::MODIFY_REPO ||
command() == ZypperCommand::RENAME_REPO ||
- command() == ZypperCommand::REFRESH)
+ command() == ZypperCommand::REFRESH ||
+ command() == ZypperCommand::CLEAN )
{
// TranslatorExplanation The %s is "--plus-repo"
cout << format(_("The %s option has no effect here, ignoring."))
@@ -917,6 +919,29 @@
break;
}
+ case ZypperCommand::CLEAN_e:
+ {
+ static struct option service_list_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"repo", required_argument, 0, 'r'},
+ {"metadata", no_argument, 0, 'm'},
+ {"all", no_argument, 0, 'a'},
+ {0, 0, 0, 0}
+ };
+ specific_options = service_list_options;
+ _command_help = _(
+ "clean\n"
+ "\n"
+ "Clean local caches.\n"
+ "\n"
+ " Command options:\n"
+ "-r, --repo Clean only only specified repositories.\n"
+ "-m, --metadata Clean metadata cache instead of package cache.\n"
+ "-a, --all Clean both metadata and package caches.\n"
+ );
+ break;
+ }
+
case ZypperCommand::LIST_UPDATES_e:
{
static struct option list_updates_options[] = {
@@ -1649,6 +1674,28 @@
return;
}
+ // --------------------------( clean )------------------------------------
+
+ else if (command() == ZypperCommand::CLEAN)
+ {
+ if (runningHelp())
+ {
+ cout << _command_help;
+ return;
+ }
+
+ // check root user
+ if (geteuid() != 0)
+ {
+ cerr << _("Root privileges are required for cleaning local caches.") << endl;
+ setExitCode(ZYPPER_EXIT_ERR_PRIVILEGES);
+ return;
+ }
+
+ clean_repos(*this);
+ return;
+ }
+
// --------------------------( remove/install )-----------------------------
else if (command() == ZypperCommand::INSTALL ||
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org