#include <boost/format.hpp>
#include <boost/logic/tribool.hpp>
#include <boost/lexical_cast.hpp>
+#include <iterator>
#include "zypp/ZYpp.h"
#include "zypp/base/Logger.h"
#include "zypp/base/IOStream.h"
+#include "zypp/base/String.h"
#include "zypp/RepoManager.h"
#include "zypp/RepoInfo.h"
void add_repo_by_url( Zypper & zypper,
const zypp::Url & url, const string & alias,
const string & type,
- tribool enabled, tribool autorefresh)
+ tribool enabled, tribool autorefresh, tribool keepPackages)
{
MIL << "going to add repository by url (alias=" << alias << ", url=" << url
<< ")" << endl;
repo.setEnabled((enabled == true));
if ( !indeterminate(autorefresh) )
repo.setAutorefresh((autorefresh == false));
+ if ( !indeterminate(keepPackages) )
+ repo.setKeepPackages(keepPackages);
add_repo(zypper, repo);
}
//! \todo handle zypp exceptions
void add_repo_from_file( Zypper & zypper,
- const std::string & repo_file_url,
- tribool enabled, tribool autorefresh)
+ const std::string & repo_file_url, tribool enabled,
+ tribool autorefresh, tribool keepPackages)
{
//! \todo handle local .repo files, validate the URI
Url url = make_url(repo_file_url);
repo.setEnabled((enabled == true));
if ( !indeterminate(autorefresh) )
repo.setAutorefresh((autorefresh == false));
+ if ( !indeterminate(keepPackages) )
+ repo.setKeepPackages(keepPackages);
MIL << "enabled: " << repo.enabled() << " autorefresh: " << repo.autorefresh() << endl;
add_repo(zypper, repo);
}
// ----------------------------------------------------------------------------
+void modify_repos_by_option( Zypper & zypper )
+{
+ RepoManager manager(zypper.globalOpts().rm_options);
+ const std::list<RepoInfo>& repos = manager.knownRepositories();
+ std::set<std::string> toModify;
+
+ if ( copts.count("all") )
+ {
+ for_(it, repos.begin(),repos.end())
+ {
+ string alias = it->alias();
+ modify_repo( zypper, alias );
+ }
+ return; //no more repository is possible
+ }
+
+ if ( copts.count("local") )
+ {
+ for_(it, repos.begin(),repos.end())
+ {
+ for_( it2,it->baseUrlsBegin(), it->baseUrlsEnd() )
+ {
+ if ( it2->isLocal() )
+ {
+ string alias = it->alias();
+ toModify.insert( alias );
+ break;
+ }
+ }
+ }
+ }
+
+ if ( copts.count("remote") )
+ {
+ for_(it, repos.begin(),repos.end())
+ {
+ for_( it2,it->baseUrlsBegin(), it->baseUrlsEnd() )
+ {
+ if ( !it2->isLocal() )
+ {
+ string alias = it->alias();
+ toModify.insert( alias );
+ break;
+ }
+ }
+ }
+ }
+
+ if ( copts.count("medium-type") )
+ {
+ string par = copts["medium-type"].front();
+ std::set<string> scheme;
+ insert_iterator<std::set<string> > ii (scheme,scheme.begin());
+ str::split( par, ii, ",");
+
+ for_(it, repos.begin(),repos.end())
+ {
+ for_( it2,it->baseUrlsBegin(), it->baseUrlsEnd() )
+ {
+ if ( scheme.find(it2->getScheme())!= scheme.end() )
+ {
+ string alias = it->alias();
+ toModify.insert( alias );
+ break;
+ }
+ }
+ }
+ }
+
+ for_(it, toModify.begin(), toModify.end())
+ {
+ modify_repo( zypper, *it );
+ }
+}
void modify_repo(Zypper & zypper, const string & alias)
{
// tell whether currenlty processed options are contradicting each other
}
DBG << "autoref = " << autoref << endl;
+ tribool keepPackages = indeterminate;
+ if (copts.count("keep-packages"))
+ keepPackages = true;
+ if (copts.count("no-keep-packages"))
+ {
+ if (keepPackages)
+ {
+ zypper.out().warning(boost::str(format(msg_contradition)
+ % "--keep-packages" % "--no-keep-package"));
+
+ keepPackages = indeterminate;
+ }
+ else
+ keepPackages = false;
+ }
+ DBG << "keepPackages = " << keepPackages << endl;
+
+
try
{
RepoManager manager(zypper.globalOpts().rm_options);
bool chnaged_enabled = false;
bool changed_autoref = false;
bool changed_prio = false;
+ bool changed_keeppackages = false;
if (!indeterminate(enable))
{
repo.setAutorefresh(autoref);
}
+ if (!indeterminate(keepPackages))
+ {
+ if (keepPackages != repo.keepPackages())
+ changed_keeppackages = true;
+ repo.setKeepPackages(keepPackages);
+ }
+
int prio = 0;
parsed_opts::const_iterator tmp1;
if ((tmp1 = zypper.cOpts().find("priority")) != zypper.cOpts().end())
}
}
- if (chnaged_enabled || changed_autoref || changed_prio)
+ if (chnaged_enabled || changed_autoref || changed_prio
+ || changed_keeppackages)
{
manager.modifyRepository(alias, repo);
_("Autorefresh has been disabled for repository '%s'.")) % alias));
}
+ if (changed_keeppackages)
+ {
+ if (repo.keepPackages())
+ zypper.out().info(boost::str(format(
+ _("Keep packages has been enabled for repository '%s'.")) % alias));
+ else
+ zypper.out().info(boost::str(format(
+ _("Keep packages has been disabled for repository '%s'.")) % alias));
+ }
+
if (changed_prio)
{
zypper.out().info(boost::str(format(
const std::string & alias,
const std::string & type = "",
boost::tribool enabled = boost::indeterminate,
- boost::tribool autorefresh = boost::indeterminate);
+ boost::tribool autorefresh = boost::indeterminate,
+ boost::tribool keepPackages = boost::indeterminate);
/**
* Add repository specified in given repo file on \a repo_file_url. All repos
void add_repo_from_file(Zypper & zypper,
const std::string & repo_file_url,
boost::tribool enabled = boost::indeterminate,
- boost::tribool autorefresh = boost::indeterminate);
+ boost::tribool autorefresh = boost::indeterminate,
+ boost::tribool keepPackages = boost::indeterminate);
+
/**
* Add repository specified by \repo to system repositories.
void modify_repo(Zypper & zypper, const std::string & alias);
/**
+ * Modify all repositories properties.
+ *
+ */
+void modify_all_repos(Zypper & zypper);
+
+/**
+ * Modify repositories which is matching filter options
+ * like all, local, remote or medium-type
+ */
+void modify_repos_by_option( Zypper & zypper );
+
+/**
* Load both repository and target resolvables.
*
* \see load_repo_resolvables(bool)
{"check", no_argument, 0, 'c'},
{"no-check", no_argument, 0, 'x'},
{"name", no_argument, 0, 'n'},
+ {"keep-packages", no_argument, 0, 'k'},
+ {"no-keep-packages", no_argument, 0, 'K'}, //TODO not documented
{0, 0, 0, 0}
};
specific_options = service_add_options;
{"no-refresh", no_argument, 0, 'n'},
{"disable-autorefresh", no_argument, 0, 0 }, // backward compatibility
{"priority", required_argument, 0, 'p'},
+ {"keep-packages", no_argument, 0, 'k'},
+ {"no-keep-packages", no_argument, 0, 'K'}, //TODO not documented
+ {"all", no_argument, 0, 'A' }, //TODO not documented
+ {"local", no_argument, 0, 'l' }, //TODO not documented
+ {"remote", no_argument, 0, 't' }, //TODO not documented
+ {"medium-type", required_argument, 0, 'm' }, //TODO not documented
{0, 0, 0, 0}
};
specific_options = service_modify_options;
if (copts.count("disable") || copts.count("disabled"))
enabled = false;
+ tribool keepPackages;
+ if (copts.count("keep-packages"))
+ keepPackages = true;
+ else if (copts.count("no-keep-packages"))
+ keepPackages = false;
+
try
{
// add repository specified in .repo file
if (copts.count("repo"))
{
- add_repo_from_file(*this,copts["repo"].front(), enabled);
+ add_repo_from_file(*this,copts["repo"].front(), enabled, keepPackages);
return;
}
}
else
{
- add_repo_from_file(*this,_arguments[0], enabled);
+ add_repo_from_file(*this,_arguments[0], enabled, keepPackages);
break;
}
case 2:
init_target(*this);
add_repo_by_url(
- *this, url, _arguments[1]/*alias*/, type, enabled);
+ *this, url, _arguments[1]/*alias*/, type, enabled, keepPackages);
return;
}
}
return;
}
- if (_arguments.size() < 1)
+ bool non_alias = copts.count("all") || copts.count("local") ||
+ copts.count("remote") || copts.count("medium-type");
+
+ if (_arguments.size() < 1 && !non_alias)
{
+ //TODO add all option to help text
out().error(_("Alias is a required argument."));
ERR << "No alias argument given." << endl;
out().info(_command_help);
return;
}
// too many arguments
- if (_arguments.size() > 1)
+ if (_arguments.size() > 1
+ || (_arguments.size() > 0 && non_alias))
{
report_too_many_arguments(_command_help);
setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
return;
}
-
- RepoInfo repo;
- if (match_repo(*this,_arguments[0],&repo))
+
+ if (non_alias)
{
- modify_repo(*this, repo.alias());
+ modify_repos_by_option(*this);
}
- else
+ else
{
- out().error(
- boost::str(format(_("Repository %s not found.")) % _arguments[0]));
- ERR << "Repo " << _arguments[0] << " not found" << endl;
+ RepoInfo repo;
+ if (match_repo(*this,_arguments[0],&repo))
+ {
+ modify_repo(*this, repo.alias());
+ }
+ else
+ {
+ out().error(
+ boost::str(format(_("Repository %s not found.")) % _arguments[0]));
+ ERR << "Repo " << _arguments[0] << " not found" << endl;
+ }
}
break;
repo.setAutorefresh(true);
repo.setAlias(TMP_RPM_REPO_ALIAS);
repo.setName(_("Plain RPM files cache"));
+ repo.setKeepPackages(false);
// shut up zypper
Out::Verbosity tmp = out().verbosity();