Zypp Commits
Threads by month
- ----- 2024 -----
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
February 2009
- 7 participants
- 171 discussions
[zypp-commit] <libzypp> SuSE-Code-11-Branch : Never refresh repositories from CD/DVD, once they are created. (bnc #476429)
by Michael Andres 22 Feb '09
by Michael Andres 22 Feb '09
22 Feb '09
ref: refs/heads/SuSE-Code-11-Branch
commit b48226689189b53a0b4c9b210d4d232f68b3df41
Author: Michael Andres <ma(a)suse.de>
Date: Sun Feb 22 15:17:42 2009 +0100
Never refresh repositories from CD/DVD, once they are created. (bnc #476429)
---
zypp/RepoManager.cc | 41 ++++++++++++++++++++++++++++-------------
1 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc
index 96657e4..f14291d 100644
--- a/zypp/RepoManager.cc
+++ b/zypp/RepoManager.cc
@@ -713,22 +713,25 @@ namespace zypp
{
MIL << "Going to try to check whether refresh is needed for " << url << endl;
- repo::RepoType repokind = info.type();
+ // first check old (cached) metadata
+ Pathname rawpath = rawmetadata_path_for_repoinfo( _pimpl->options, info );
+ filesystem::assert_dir(rawpath);
+ oldstatus = metadataStatus(info);
- // if the type is unknown, try probing.
- switch ( repokind.toEnum() )
+ if ( oldstatus.empty() )
{
- case RepoType::NONE_e:
- // unknown, probe it
- repokind = probe(url);
- break;
- default:
- break;
+ MIL << "No cached metadata, going to refresh" << endl;
+ return REFRESH_NEEDED;
}
- Pathname rawpath = rawmetadata_path_for_repoinfo( _pimpl->options, info );
- filesystem::assert_dir(rawpath);
- oldstatus = metadataStatus(info);
+ {
+ std::string scheme( url.getScheme() );
+ if ( scheme == "cd" || scheme == "dvd" )
+ {
+ MIL << "never refresh CD/DVD" << endl;
+ return REPO_UP_TO_DATE;
+ }
+ }
// now we've got the old (cached) status, we can decide repo.refresh.delay
if (policy != RefreshForced && policy != RefreshIfNeededIgnoreDelay)
@@ -752,9 +755,21 @@ namespace zypp
}
}
- // create temp dir as sibling of rawpath
+ // To test the new matadta create temp dir as sibling of rawpath
filesystem::TmpDir tmpdir( filesystem::TmpDir::makeSibling( rawpath ) );
+ repo::RepoType repokind = info.type();
+ // if the type is unknown, try probing.
+ switch ( repokind.toEnum() )
+ {
+ case RepoType::NONE_e:
+ // unknown, probe it
+ repokind = probe(url);
+ break;
+ default:
+ break;
+ }
+
if ( ( repokind.toEnum() == RepoType::RPMMD_e ) ||
( repokind.toEnum() == RepoType::YAST2_e ) )
{
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <libzypp> master : big MediaCurl refactoring, to share the settings initialization with
by Duncan Mac-Vicar P 22 Feb '09
by Duncan Mac-Vicar P 22 Feb '09
22 Feb '09
ref: refs/heads/master
commit 4cba0723fb6f61ea1b4a0d91bc0dfcfec5b43bbd
Author: Duncan Mac-Vicar P <dmacvicar(a)suse.de>
Date: Sun Feb 22 02:00:25 2009 +0100
big MediaCurl refactoring, to share the settings initialization with
MediaAria2c.
- replace lot of curl_easy_setop with exception checking to a
macro to reduce duplicated code
- implement download.min_download_speed (default no limit)
download.max_download_speed (default no limit) for MediaCurl as well
Still thinking if MediaCurl should be still the default for https, because
aria does not support a CA dir (only files)
---
zypp/media/MediaAria2c.cc | 152 -----------
zypp/media/MediaAria2c.h | 2 -
zypp/media/MediaCurl.cc | 546 +++++++++++++++++-----------------------
zypp/media/MediaCurl.h | 27 ++-
zypp/media/TransferSettings.cc | 64 +++++
zypp/media/TransferSettings.h | 48 ++++
6 files changed, 368 insertions(+), 471 deletions(-)
diff --git a/zypp/media/MediaAria2c.cc b/zypp/media/MediaAria2c.cc
index e9d04e4..8d00e78 100644
--- a/zypp/media/MediaAria2c.cc
+++ b/zypp/media/MediaAria2c.cc
@@ -26,7 +26,6 @@
#include "zypp/Target.h"
#include "zypp/ZYppFactory.h"
-#include "zypp/media/TransferProgram.h"
#include "zypp/media/MediaAria2c.h"
#include "zypp/media/proxyinfo/ProxyInfos.h"
#include "zypp/media/ProxyInfo.h"
@@ -75,84 +74,6 @@ MediaAria2c::existsAria2cmd()
return ( aria.close() == 0 );
}
-void fillSettingsFromUrl( const Url &url, TransferSettings &s )
-{
- std::string param(url.getQueryParam("timeout"));
- if( !param.empty())
- {
- long num = str::strtonum<long>(param);
- if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX)
- s.setTimeout(num);
- }
-
- if ( ! url.getUsername().empty() )
- {
- s.setUsername(url.getUsername());
- if ( url.getPassword().size() )
- {
- s.setPassword(url.getPassword());
- }
- }
-
- string proxy = url.getQueryParam( "proxy" );
-
- if ( ! proxy.empty() )
- {
- string proxyport( url.getQueryParam( "proxyport" ) );
- if ( ! proxyport.empty() ) {
- proxy += ":" + proxyport;
- }
- s.setProxy(proxy);
- s.setProxyEnabled(true);
- }
-}
-
-void fillSettingsSystemProxy( const Url&url, TransferSettings &s )
-{
- ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
-
- if ( proxy_info.enabled())
- {
- s.setProxyEnabled(true);
- std::list<std::string> nope = proxy_info.noProxy();
- for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
- it != proxy_info.noProxyEnd();
- it++)
- {
- std::string host( str::toLower(url.getHost()));
- std::string temp( str::toLower(*it));
-
- // no proxy if it points to a suffix
- // preceeded by a '.', that maches
- // the trailing portion of the host.
- if( temp.size() > 1 && temp.at(0) == '.')
- {
- if(host.size() > temp.size() &&
- host.compare(host.size() - temp.size(), temp.size(), temp) == 0)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- s.setProxyEnabled(false);
- break;
- }
- }
- else
- // no proxy if we have an exact match
- if( host == temp)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- s.setProxyEnabled(false);
- break;
- }
- }
-
- if ( s.proxyEnabled() )
- s.setProxy(proxy_info.proxy(url.getScheme()));
- }
-
-}
-
/**
* comannd line for aria.
* The argument list gets passed as reference
@@ -250,38 +171,6 @@ void fillAriaCmdLine( const Pathname &ariapath,
args.push_back(url.asString().c_str());
}
-static const char *const anonymousIdHeader()
-{
- // we need to add the release and identifier to the
- // agent string.
- // The target could be not initialized, and then this information
- // is not available.
- Target_Ptr target = zypp::getZYpp()->getTarget();
-
- static const std::string _value(
- str::form(
- "X-Zypp-AnonymousId: %s",
- target ? target->anonymousUniqueId().c_str() : "" )
- );
- return _value.c_str();
-}
-
-static const char *const distributionFlavorHeader()
-{
- // we need to add the release and identifier to the
- // agent string.
- // The target could be not initialized, and then this information
- // is not available.
- Target_Ptr target = zypp::getZYpp()->getTarget();
-
- static const std::string _value(
- str::trim( str::form(
- "X-ZYpp-DistributionFlavor: %s",
- target ? target->distributionFlavor().c_str() : "" ) )
- );
- return _value.c_str();
-}
-
const char *const MediaAria2c::agentString()
{
// we need to add the release and identifier to the
@@ -309,28 +198,6 @@ MediaAria2c::MediaAria2c( const Url & url_r,
{
MIL << "MediaAria2c::MediaAria2c(" << url_r << ", " << attach_point_hint_r << ")" << endl;
- /*
- if( !attachPoint().empty())
- {
- PathInfo ainfo(attachPoint());
- Pathname apath(attachPoint() + "XXXXXX");
- char *atemp = ::strdup( apath.asString().c_str());
- char *atest = NULL;
- if( !ainfo.isDir() || !ainfo.userMayRWX() ||
- atemp == NULL || (atest=::mkdtemp(atemp)) == NULL)
- {
- WAR << "attach point " << ainfo.path()
- << " is not useable for " << url_r.getScheme() << endl;
- setAttachPoint("", true);
- }
- else if( atest != NULL)
- ::rmdir(atest);
-
- if( atemp != NULL)
- ::free(atemp);
- }
- */
-
//At this point, we initialize aria2c path
_aria2cPath = Pathname( whereisAria2c().asString() );
@@ -341,25 +208,7 @@ MediaAria2c::MediaAria2c( const Url & url_r,
void MediaAria2c::attachTo (bool next)
{
MediaCurl::attachTo(next);
-
_settings.setUserAgentString(agentString());
- _settings.addHeader(anonymousIdHeader());
- _settings.addHeader(distributionFlavorHeader());
-
- _settings.setTimeout(TRANSFER_TIMEOUT);
- _settings.setConnectTimeout(CONNECT_TIMEOUT);
-
- // fill some settings from url query parameters
- fillSettingsFromUrl(_url, _settings);
-
- // if the proxy was not set by url, then look
- if ( _settings.proxy().empty() )
- {
- // at the system proxy settings
- fillSettingsSystemProxy(_url, _settings);
- }
-
- DBG << "Proxy: " << (_settings.proxy().empty() ? "-none-" : _settings.proxy()) << endl;
}
bool
@@ -371,7 +220,6 @@ MediaAria2c::checkAttachPoint(const Pathname &apoint) const
void MediaAria2c::disconnectFrom()
{
MediaCurl::disconnectFrom();
-
}
void MediaAria2c::releaseFrom( const std::string & ejectDev )
diff --git a/zypp/media/MediaAria2c.h b/zypp/media/MediaAria2c.h
index 33d49f7..544cc8f 100644
--- a/zypp/media/MediaAria2c.h
+++ b/zypp/media/MediaAria2c.h
@@ -107,8 +107,6 @@ class MediaAria2c : public MediaCurl {
/** External process to get aria2c version */
std::string getAria2cVersion();
static std::string _aria2cVersion;
-
- TransferSettings _settings;
};
///////////////////////////////////////////////////////////////////
diff --git a/zypp/media/MediaCurl.cc b/zypp/media/MediaCurl.cc
index 280c9a7..af797d2 100644
--- a/zypp/media/MediaCurl.cc
+++ b/zypp/media/MediaCurl.cc
@@ -183,6 +183,129 @@ namespace zypp {
//
///////////////////////////////////////////////////////////////////
+void fillSettingsFromUrl( const Url &url, TransferSettings &s )
+{
+ std::string param(url.getQueryParam("timeout"));
+ if( !param.empty())
+ {
+ long num = str::strtonum<long>(param);
+ if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX)
+ s.setTimeout(num);
+ }
+
+ if ( ! url.getUsername().empty() )
+ {
+ s.setUsername(url.getUsername());
+ if ( url.getPassword().size() )
+ s.setPassword(url.getPassword());
+ }
+ else
+ {
+ // if there is no username, set anonymous auth
+ if ( url.getScheme() == "ftp" && s.username().empty() )
+ s.setAnonymousAuth();
+ }
+
+ if ( url.getScheme() == "https" )
+ {
+ s.setVerifyPeerEnabled(false);
+ s.setVerifyHostEnabled(false);
+
+ std::string verify( url.getQueryParam("ssl_verify"));
+ if( verify.empty() ||
+ verify == "yes")
+ {
+ s.setVerifyPeerEnabled(true);
+ s.setVerifyHostEnabled(true);
+ }
+ else if( verify == "no")
+ {
+ s.setVerifyPeerEnabled(false);
+ s.setVerifyHostEnabled(false);
+ }
+ else
+ {
+ std::vector<std::string> flags;
+ std::vector<std::string>::const_iterator flag;
+ str::split( verify, std::back_inserter(flags), ",");
+ for(flag = flags.begin(); flag != flags.end(); ++flag)
+ {
+ if( *flag == "host")
+ s.setVerifyHostEnabled(true);
+ else if( *flag == "peer")
+ s.setVerifyPeerEnabled(true);
+ else
+ ZYPP_THROW(MediaBadUrlException(url, "Unknown ssl_verify flag"));
+ }
+ }
+ }
+
+ Pathname ca_path = Pathname(url.getQueryParam("ssl_capath")).asString();
+ if( ! ca_path.empty())
+ {
+ if( !PathInfo(ca_path).isDir() || !Pathname(ca_path).absolute())
+ ZYPP_THROW(MediaBadUrlException(url, "Invalid ssl_capath path"));
+ else
+ s.setCertificateAuthoritiesPath(ca_path);
+ }
+
+ string proxy = url.getQueryParam( "proxy" );
+ if ( ! proxy.empty() )
+ {
+ string proxyport( url.getQueryParam( "proxyport" ) );
+ if ( ! proxyport.empty() ) {
+ proxy += ":" + proxyport;
+ }
+ s.setProxy(proxy);
+ s.setProxyEnabled(true);
+ }
+}
+
+void fillSettingsSystemProxy( const Url&url, TransferSettings &s )
+{
+ ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
+
+ if ( proxy_info.enabled())
+ {
+ s.setProxyEnabled(true);
+ std::list<std::string> nope = proxy_info.noProxy();
+ for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
+ it != proxy_info.noProxyEnd();
+ it++)
+ {
+ std::string host( str::toLower(url.getHost()));
+ std::string temp( str::toLower(*it));
+
+ // no proxy if it points to a suffix
+ // preceeded by a '.', that maches
+ // the trailing portion of the host.
+ if( temp.size() > 1 && temp.at(0) == '.')
+ {
+ if(host.size() > temp.size() &&
+ host.compare(host.size() - temp.size(), temp.size(), temp) == 0)
+ {
+ DBG << "NO_PROXY: '" << *it << "' matches host '"
+ << host << "'" << endl;
+ s.setProxyEnabled(false);
+ break;
+ }
+ }
+ else
+ // no proxy if we have an exact match
+ if( host == temp)
+ {
+ DBG << "NO_PROXY: '" << *it << "' matches host '"
+ << host << "'" << endl;
+ s.setProxyEnabled(false);
+ break;
+ }
+ }
+
+ if ( s.proxyEnabled() )
+ s.setProxy(proxy_info.proxy(url.getScheme()));
+ }
+}
+
Pathname MediaCurl::_cookieFile = "/var/lib/YaST2/cookies";
static const char *const anonymousIdHeader()
@@ -217,7 +340,6 @@ static const char *const distributionFlavorHeader()
return _value.c_str();
}
-
static const char *const agentString()
{
// we need to add the release and identifier to the
@@ -237,7 +359,15 @@ static const char *const agentString()
return _value.c_str();
}
-
+// we use this define to unbloat code
+#define SET_OPTION(opt,val) { \
+ ret = curl_easy_setopt ( _curl, opt, val ); \
+ if ( ret != 0) { \
+ disconnectFrom(); \
+ ZYPP_THROW(MediaCurlSetOptException(_url, _curlError)); \
+ } \
+ }
+
MediaCurl::MediaCurl( const Url & url_r,
const Pathname & attach_point_hint_r )
: MediaHandler( url_r, attach_point_hint_r,
@@ -280,13 +410,7 @@ void MediaCurl::setCookieFile( const Pathname &fileName )
}
///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaCurl::attachTo
-// METHOD TYPE : PMError
-//
-// DESCRIPTION : Asserted that not already attached, and attachPoint is a directory.
-//
+
void MediaCurl::attachTo (bool next)
{
if ( next )
@@ -353,148 +477,66 @@ void MediaCurl::attachTo (bool next)
ZYPP_THROW(MediaCurlSetOptException(_url, "Error setting error buffer"));
}
- ret = curl_easy_setopt( _curl, CURLOPT_FAILONERROR, true );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
+ SET_OPTION(CURLOPT_FAILONERROR,true);
+ SET_OPTION(CURLOPT_NOSIGNAL, 1);
- ret = curl_easy_setopt( _curl, CURLOPT_NOSIGNAL, 1 );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
+ // add custom headers
+ _settings.addHeader(anonymousIdHeader());
+ _settings.addHeader(distributionFlavorHeader());
+ _settings.addHeader("Pragma:");
- /**
- * Transfer timeout
- */
- {
- _xfer_timeout = TRANSFER_TIMEOUT;
+ _settings.setTimeout(TRANSFER_TIMEOUT);
+ _settings.setConnectTimeout(CONNECT_TIMEOUT);
- std::string param(_url.getQueryParam("timeout"));
- if( !param.empty())
- {
- long num = str::strtonum<long>( param);
- if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX)
- _xfer_timeout = num;
- }
- }
+ _settings.setUserAgentString(agentString());
- /*
- ** Connect timeout
- */
- ret = curl_easy_setopt( _curl, CURLOPT_CONNECTTIMEOUT, CONNECT_TIMEOUT);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
+ // fill some settings from url query parameters
+ try
+ {
+ fillSettingsFromUrl(_url, _settings);
}
-
- if ( _url.getScheme() == "http" ) {
- // follow any Location: header that the server sends as part of
- // an HTTP header (#113275)
- ret = curl_easy_setopt ( _curl, CURLOPT_FOLLOWLOCATION, true );
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
- ret = curl_easy_setopt ( _curl, CURLOPT_MAXREDIRS, 3L );
- if ( ret != 0) {
+ catch ( const MediaException &e )
+ {
disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
+ ZYPP_RETHROW(e);
+ }
+
+ // if the proxy was not set by url, then look
+ if ( _settings.proxy().empty() )
+ {
+ // at the system proxy settings
+ fillSettingsSystemProxy(_url, _settings);
+ }
- ret = curl_easy_setopt ( _curl, CURLOPT_USERAGENT, agentString() );
+ DBG << "Proxy: " << (_settings.proxy().empty() ? "-none-" : _settings.proxy()) << endl;
+ /**
+ * Connect timeout
+ */
+ SET_OPTION(CURLOPT_CONNECTTIMEOUT, _settings.connectTimeout());
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
+ if ( _url.getScheme() == "http" )
+ {
+ // follow any Location: header that the server sends as part of
+ // an HTTP header (#113275)
+ SET_OPTION(CURLOPT_FOLLOWLOCATION, true);
+ SET_OPTION(CURLOPT_MAXREDIRS, 3L);
+ SET_OPTION(CURLOPT_USERAGENT, _settings.userAgentString().c_str() );
}
if ( _url.getScheme() == "https" )
{
- bool verify_peer = false;
- bool verify_host = false;
-
- std::string verify( _url.getQueryParam("ssl_verify"));
- if( verify.empty() ||
- verify == "yes")
- {
- verify_peer = true;
- verify_host = true;
- }
- else
- if( verify == "no")
- {
- verify_peer = false;
- verify_host = false;
- }
- else
- {
- std::vector<std::string> flags;
- std::vector<std::string>::const_iterator flag;
- str::split( verify, std::back_inserter(flags), ",");
- for(flag = flags.begin(); flag != flags.end(); ++flag)
- {
- if( *flag == "host")
- {
- verify_host = true;
- }
- else
- if( *flag == "peer")
- {
- verify_peer = true;
- }
- else
- {
- disconnectFrom();
- ZYPP_THROW(MediaBadUrlException(_url, "Unknown ssl_verify flag"));
- }
- }
- }
-
- _ca_path = Pathname(_url.getQueryParam("ssl_capath")).asString();
- if( _ca_path.empty())
- {
- _ca_path = "/etc/ssl/certs/";
- }
- else
- if( !PathInfo(_ca_path).isDir() || !Pathname(_ca_path).absolute())
- {
- disconnectFrom();
- ZYPP_THROW(MediaBadUrlException(_url, "Invalid ssl_capath path"));
- }
-
- if( verify_peer || verify_host)
+ if( _settings.verifyPeerEnabled() ||
+ _settings.verifyHostEnabled() )
{
- ret = curl_easy_setopt( _curl, CURLOPT_CAPATH, _ca_path.c_str());
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_SSL_VERIFYPEER, verify_peer ? 1L : 0L);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
- ret = curl_easy_setopt( _curl, CURLOPT_SSL_VERIFYHOST, verify_host ? 2L : 0L);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt ( _curl, CURLOPT_USERAGENT, agentString() );
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
+ SET_OPTION(CURLOPT_CAPATH, _settings.certificateAuthoritiesPath().c_str());
}
+ SET_OPTION(CURLOPT_SSL_VERIFYPEER, _settings.verifyPeerEnabled() ? 1L : 0L);
+ SET_OPTION(CURLOPT_SSL_VERIFYHOST, _settings.verifyHostEnabled() ? 2L : 0L);
+ SET_OPTION(CURLOPT_USERAGENT, _settings.userAgentString().c_str() );
}
-
/*---------------------------------------------------------------*
CURLOPT_USERPWD: [user name]:[password]
@@ -502,27 +544,12 @@ void MediaCurl::attachTo (bool next)
If not provided, anonymous FTP identification
*---------------------------------------------------------------*/
- if ( _url.getUsername().empty() ) {
- if ( _url.getScheme() == "ftp" ) {
- string id = "yast2@";
- id += VERSION;
- DBG << "Anonymous FTP identification: '" << id << "'" << endl;
- _userpwd = "anonymous:" + id;
- }
- } else {
- _userpwd = _url.getUsername();
- if ( _url.getPassword().size() ) {
- _userpwd += ":" + _url.getPassword();
- }
- }
+ if ( _settings.userPassword().size() )
+ {
+ SET_OPTION(CURLOPT_USERPWD, unEscape(_settings.userPassword()).c_str());
- if ( _userpwd.size() ) {
- _userpwd = unEscape( _userpwd );
- ret = curl_easy_setopt( _curl, CURLOPT_USERPWD, _userpwd.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
+ //FIXME, we leave this here for now, as it does not make sense yet
+ // to refactor it to the fill settings from url function
// HTTP authentication type
if(_url.getScheme() == "http" || _url.getScheme() == "https")
@@ -539,11 +566,7 @@ void MediaCurl::attachTo (bool next)
DBG << "Enabling HTTP authentication methods: " << use_auth
<< " (CURLOPT_HTTPAUTH=" << auth << ")" << std::endl;
- ret = curl_easy_setopt( _curl, CURLOPT_HTTPAUTH, auth);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
+ SET_OPTION(CURLOPT_HTTPAUTH, auth);
}
}
catch (MediaException & ex_r)
@@ -560,177 +583,72 @@ void MediaCurl::attachTo (bool next)
}
}
- /*---------------------------------------------------------------*
- CURLOPT_PROXY: host[:port]
-
- Url::option(proxy and proxyport) -> CURLOPT_PROXY
- If not provided, /etc/sysconfig/proxy is evaluated
- *---------------------------------------------------------------*/
-
- _proxy = _url.getQueryParam( "proxy" );
-
- if ( ! _proxy.empty() ) {
- string proxyport( _url.getQueryParam( "proxyport" ) );
- if ( ! proxyport.empty() ) {
- _proxy += ":" + proxyport;
- }
- } else {
-
- ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
-
- if ( proxy_info.enabled())
+ if ( _settings.proxyEnabled() )
+ {
+ if ( ! _settings.proxy().empty() )
{
- bool useproxy = true;
-
- std::list<std::string> nope = proxy_info.noProxy();
- for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
- it != proxy_info.noProxyEnd();
- it++)
+ SET_OPTION(CURLOPT_PROXY, _settings.proxy().c_str());
+ /*---------------------------------------------------------------*
+ CURLOPT_PROXYUSERPWD: [user name]:[password]
+
+ Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
+ If not provided, $HOME/.curlrc is evaluated
+ *---------------------------------------------------------------*/
+
+ string proxyuserpwd = _settings.proxyUserPassword();
+
+ if ( proxyuserpwd.empty() )
{
- std::string host( str::toLower(_url.getHost()));
- std::string temp( str::toLower(*it));
-
- // no proxy if it points to a suffix
- // preceeded by a '.', that maches
- // the trailing portion of the host.
- if( temp.size() > 1 && temp.at(0) == '.')
- {
- if(host.size() > temp.size() &&
- host.compare(host.size() - temp.size(), temp.size(), temp) == 0)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
- }
- }
+ if (curlconf.proxyuserpwd.empty())
+ DBG << "~/.curlrc does not contain the proxy-user option" << endl;
else
- // no proxy if we have an exact match
- if( host == temp)
{
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
+ proxyuserpwd = curlconf.proxyuserpwd;
+ DBG << "using proxy-user from ~/.curlrc" << endl;
}
}
- if ( useproxy ) {
- _proxy = proxy_info.proxy(_url.getScheme());
- }
+ proxyuserpwd = unEscape( proxyuserpwd );
+ if ( ! proxyuserpwd.empty() )
+ SET_OPTION(CURLOPT_PROXYUSERPWD, proxyuserpwd.c_str());
}
}
-
-
- DBG << "Proxy: " << (_proxy.empty() ? "-none-" : _proxy) << endl;
-
- if ( ! _proxy.empty() ) {
-
- ret = curl_easy_setopt( _curl, CURLOPT_PROXY, _proxy.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
-
- /*---------------------------------------------------------------*
- CURLOPT_PROXYUSERPWD: [user name]:[password]
-
- Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
- If not provided, $HOME/.curlrc is evaluated
- *---------------------------------------------------------------*/
-
- _proxyuserpwd = _url.getQueryParam( "proxyuser" );
-
- if ( ! _proxyuserpwd.empty() ) {
- string proxypassword( _url.getQueryParam( "proxypassword" ) );
- if ( ! proxypassword.empty() ) {
- _proxyuserpwd += ":" + proxypassword;
- }
- } else {
- if (curlconf.proxyuserpwd.empty())
- DBG << "~/.curlrc does not contain the proxy-user option" << endl;
- else
- {
- _proxyuserpwd = curlconf.proxyuserpwd;
- DBG << "using proxy-user from ~/.curlrc" << endl;
- }
- }
-
- _proxyuserpwd = unEscape( _proxyuserpwd );
- if ( ! _proxyuserpwd.empty() ) {
- ret = curl_easy_setopt( _curl, CURLOPT_PROXYUSERPWD, _proxyuserpwd.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
- }
+
+ /** Speed limits */
+ if ( _settings.minDownloadSpeed() != 0 )
+ {
+ SET_OPTION(CURLOPT_LOW_SPEED_LIMIT, _settings.minDownloadSpeed());
+ // default to 10 seconds at low speed
+ SET_OPTION(CURLOPT_LOW_SPEED_TIME, 10);
}
+
+ if ( _settings.maxDownloadSpeed() != 0 )
+ SET_OPTION(CURLOPT_MAX_RECV_SPEED_LARGE, _settings.maxDownloadSpeed());
/*---------------------------------------------------------------*
*---------------------------------------------------------------*/
_currentCookieFile = _cookieFile.asString();
-
- ret = curl_easy_setopt( _curl, CURLOPT_COOKIEFILE,
- _currentCookieFile.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_COOKIEJAR,
- _currentCookieFile.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_PROGRESSFUNCTION,
- &progressCallback );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_NOPROGRESS, false );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
+ SET_OPTION(CURLOPT_COOKIEFILE, _currentCookieFile.c_str() );
+ SET_OPTION(CURLOPT_COOKIEJAR, _currentCookieFile.c_str() );
+ SET_OPTION(CURLOPT_PROGRESSFUNCTION, &progressCallback );
+ SET_OPTION(CURLOPT_NOPROGRESS, false );
// bnc #306272
- ret = curl_easy_setopt( _curl, CURLOPT_PROXY_TRANSFER_MODE, 1 );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
-
- _customHeaders = curl_slist_append(_customHeaders, "Pragma:");
-
- if ( !_customHeaders ) {
- ZYPP_THROW(MediaCurlInitException(_url));
- }
-
- // now add the anonymous id header
- _customHeaders = curl_slist_append(_customHeaders, anonymousIdHeader());
+ SET_OPTION(CURLOPT_PROXY_TRANSFER_MODE, 1 );
- if ( !_customHeaders ) {
- ZYPP_THROW(MediaCurlInitException(_url));
- }
-
- // now add the product flavor header
- _customHeaders = curl_slist_append(_customHeaders, distributionFlavorHeader());
-
- if ( !_customHeaders ) {
- ZYPP_THROW(MediaCurlInitException(_url));
+ // append settings custom headers to curl
+ for ( TransferSettings::Headers::const_iterator it = _settings.headersBegin();
+ it != _settings.headersEnd();
+ ++it )
+ {
+
+ _customHeaders = curl_slist_append(_customHeaders, it->c_str());
+ if ( !_customHeaders )
+ ZYPP_THROW(MediaCurlInitException(_url));
}
- ret = curl_easy_setopt ( _curl, CURLOPT_HTTPHEADER, _customHeaders );
-
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
- }
+ SET_OPTION(CURLOPT_HTTPHEADER, _customHeaders);
// FIXME: need a derived class to propelly compare url's
MediaSourceRef media( new MediaSource(_url.getScheme(), _url.asString()));
@@ -1163,7 +1081,7 @@ bool MediaCurl::doGetDoesFileExist( const Pathname & filename ) const
}
-void MediaCurl::doGetFileCopy( const Pathname & filename , const Pathname & target, callback::SendReport<DownloadProgressReport> & report) const
+void MediaCurl::doGetFileCopy( const Pathname & filename , const Pathname & target, callback::SendReport<DownloadProgressReport> & report, RequestOptions options ) const
{
DBG << filename.asString() << endl;
@@ -1262,7 +1180,7 @@ void MediaCurl::doGetFileCopy( const Pathname & filename , const Pathname & targ
}
// Set callback and perform.
- ProgressData progressData(_xfer_timeout, url, &report);
+ ProgressData progressData(_settings.timeout(), url, &report);
report->start(url, dest);
if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, &progressData ) != 0 ) {
WAR << "Can't set CURLOPT_PROGRESSDATA: " << _curlError << endl;;
@@ -1734,10 +1652,12 @@ bool MediaCurl::authenticate(const string & availAuthTypes, bool firstTry) const
// set username and password
if (credentials)
{
- _userpwd = credentials->getUserPwd();
+ // HACK, why is this const?
+ const_cast<MediaCurl*>(this)->_settings.setUsername(credentials->username());
+ const_cast<MediaCurl*>(this)->_settings.setPassword(credentials->password());
// set username and password
- CURLcode ret = curl_easy_setopt(_curl, CURLOPT_USERPWD, _userpwd.c_str());
+ CURLcode ret = curl_easy_setopt(_curl, CURLOPT_USERPWD, _settings.userPassword().c_str());
if ( ret != 0 ) ZYPP_THROW(MediaCurlSetOptException(_url, _curlError));
// set available authentication types from the exception
diff --git a/zypp/media/MediaCurl.h b/zypp/media/MediaCurl.h
index 248341b..6be4bdb 100644
--- a/zypp/media/MediaCurl.h
+++ b/zypp/media/MediaCurl.h
@@ -12,6 +12,8 @@
#ifndef ZYPP_MEDIA_MEDIACURL_H
#define ZYPP_MEDIA_MEDIACURL_H
+#include "zypp/base/Flags.h"
+#include "zypp/media/TransferSettings.h"
#include "zypp/media/MediaHandler.h"
#include "zypp/ZYppCallbacks.h"
@@ -27,7 +29,19 @@ namespace zypp {
* @short Implementation class for FTP, HTTP and HTTPS MediaHandler
* @see MediaHandler
**/
-class MediaCurl : public MediaHandler {
+class MediaCurl : public MediaHandler
+{
+ public:
+ enum RequestOption
+ {
+ /** Defaults */
+ OPTION_NONE = 0x0,
+ /** retrieve only a range of the file */
+ OPTION_RANGE = 0x1,
+ /** only issue a HEAD (or equivalent) request */
+ OPTION_HEAD = 0x02,
+ };
+ ZYPP_DECLARE_FLAGS(RequestOptions,RequestOption);
protected:
@@ -69,7 +83,7 @@ class MediaCurl : public MediaHandler {
* \throws MediaException
*
*/
- virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report) const;
+ virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report, RequestOptions options = OPTION_NONE ) const;
virtual bool checkAttachPoint(const Pathname &apoint) const;
@@ -109,15 +123,20 @@ class MediaCurl : public MediaHandler {
long _curlDebug;
curl_slist *_customHeaders;
+ /*
mutable std::string _userpwd;
std::string _proxy;
std::string _proxyuserpwd;
+ */
std::string _currentCookieFile;
- std::string _ca_path;
- long _xfer_timeout;
+ //std::string _ca_path;
+ //long _xfer_timeout;
static Pathname _cookieFile;
+protected:
+ TransferSettings _settings;
};
+ZYPP_DECLARE_OPERATORS_FOR_FLAGS(MediaCurl::RequestOptions);
///////////////////////////////////////////////////////////////////
diff --git a/zypp/media/TransferSettings.cc b/zypp/media/TransferSettings.cc
index b206d1b..e822f27 100644
--- a/zypp/media/TransferSettings.cc
+++ b/zypp/media/TransferSettings.cc
@@ -32,6 +32,9 @@ public:
, _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
, _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
, _maxSilentTries(ZConfig::instance().download_max_silent_tries())
+ , _verify_host(false)
+ , _verify_peer(false)
+ , _ca_path("/etc/ssl/certs")
{}
virtual ~Impl()
@@ -68,6 +71,10 @@ public:
long _minDownloadSpeed;
long _maxDownloadSpeed;
long _maxSilentTries;
+
+ bool _verify_host;
+ bool _verify_peer;
+ Pathname _ca_path;
};
TransferSettings::TransferSettings()
@@ -116,11 +123,27 @@ void TransferSettings::setPassword( const std::string &password )
_impl->_password = password;
}
+void TransferSettings::setAnonymousAuth()
+{
+ setUsername("anonymous");
+ string id = "yast@";
+ setPassword(id + VERSION);
+}
+
std::string TransferSettings::password() const
{
return _impl->_password;
}
+std::string TransferSettings::userPassword() const
+{
+ string userpwd = username();
+ if ( password().size() ) {
+ userpwd += ":" + password();
+ }
+ return userpwd;
+}
+
void TransferSettings::setProxyEnabled( bool enabled )
{
_impl->_useproxy = enabled;
@@ -161,6 +184,15 @@ std::string TransferSettings::proxyPassword() const
return _impl->_proxy_password;
}
+std::string TransferSettings::proxyUserPassword() const
+{
+ string userpwd = proxyUsername();
+ if ( proxyPassword().size() ) {
+ userpwd += ":" + proxyPassword();
+ }
+ return userpwd;
+}
+
void TransferSettings::setTimeout( long t )
{
_impl->_timeout = t;
@@ -221,6 +253,38 @@ void TransferSettings::setMaxSilentTries(long v)
_impl->_maxSilentTries = v;
}
+bool TransferSettings::verifyHostEnabled() const
+{
+ return _impl->_verify_host;
+}
+
+void TransferSettings::setVerifyHostEnabled( bool enabled )
+{
+ _impl->_verify_host = enabled;
+}
+
+bool TransferSettings::verifyPeerEnabled() const
+{
+ return _impl->_verify_peer;
+}
+
+
+void TransferSettings::setVerifyPeerEnabled( bool enabled )
+{
+ _impl->_verify_peer = enabled;
+}
+
+Pathname TransferSettings::certificateAuthoritiesPath() const
+{
+ return _impl->_ca_path;
+}
+
+void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
+{
+ _impl->_ca_path = path;
+}
+
+
} // ns media
} // ns zypp
diff --git a/zypp/media/TransferSettings.h b/zypp/media/TransferSettings.h
index 1491bb7..567fff9 100644
--- a/zypp/media/TransferSettings.h
+++ b/zypp/media/TransferSettings.h
@@ -79,6 +79,17 @@ public:
std::string password() const;
/**
+ * returns the user and password as
+ * a user:pass string
+ */
+ std::string userPassword() const;
+
+ /**
+ * sets anonymous authentication (ie: for ftp)
+ */
+ void setAnonymousAuth();
+
+ /**
* whether the proxy is used or not
*/
void setProxyEnabled( bool enabled );
@@ -119,6 +130,12 @@ public:
std::string proxyPassword() const;
/**
+ * returns the proxy user and password as
+ * a user:pass string
+ */
+ std::string proxyUserPassword() const;
+
+ /**
* set the connect timeout
*/
void setConnectTimeout( long t );
@@ -180,6 +197,37 @@ public:
*/
void setMaxSilentTries(long v);
+ /**
+ * Whether to verify host for ssl
+ */
+ bool verifyHostEnabled() const;
+
+ /**
+ * Sets whether to verify host for ssl
+ */
+ void setVerifyHostEnabled( bool enabled );
+
+ /**
+ * Whether to verify peer for ssl
+ */
+ bool verifyPeerEnabled() const;
+
+ /**
+ * Sets whether to verify host for ssl
+ */
+ void setVerifyPeerEnabled( bool enabled );
+
+ /**
+ * SSL certificate authorities path
+ * ( default: /etc/ssl/certs )
+ */
+ Pathname certificateAuthoritiesPath() const;
+
+ /**
+ * Sets the SSL certificate authorities path
+ */
+ void setCertificateAuthoritiesPath( const zypp::Pathname &path );
+
protected:
class Impl;
RWCOW_pointer<Impl> _impl;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
ref: refs/heads/master
commit 25f2cf632142130b18d7996e42a163723257b149
Author: Duncan Mac-Vicar P <dmacvicar(a)suse.de>
Date: Sat Feb 21 18:32:34 2009 +0100
changes
---
package/libzypp.changes | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/package/libzypp.changes b/package/libzypp.changes
index 8a0df32..da94ae3 100644
--- a/package/libzypp.changes
+++ b/package/libzypp.changes
@@ -1,4 +1,14 @@
-------------------------------------------------------------------
+Sat Feb 21 18:31:17 CET 2009 - dmacvicar(a)suse.de
+
+Implemented the following options with aria backend:
+
+- download.max_concurrent_connections (default 2)
+ download.min_download_speed (default no limit)
+ download.max_download_speed (default no limit)
+ download.max_silent_tries (default 5)
+
+-------------------------------------------------------------------
Fri Feb 20 16:28:19 CET 2009 - dmacvicar(a)suse.de
- MediaAria2c: allow disabling aria2 using ZYPP_ARIA2C=0.
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <libzypp> master : finally I saw the light, MediaAria2 now inherits MediaCurl, therefore
by Duncan Mac-Vicar P 21 Feb '09
by Duncan Mac-Vicar P 21 Feb '09
21 Feb '09
ref: refs/heads/master
commit 21b807b024cbe0d1bcc41a9ceb5c27c1eadf7eaf
Author: Duncan Mac-Vicar P <dmacvicar(a)suse.de>
Date: Sat Feb 21 18:28:12 2009 +0100
finally I saw the light, MediaAria2 now inherits MediaCurl, therefore
has access to curl methods, or any functionality which aria does not provides.
Implemented the following options with aria:
download.max_concurrent_connections (default 2)
download.min_download_speed (default no limit)
download.max_download_speed (default no limit)
download.max_silent_tries (default 5)
Lot of duplicated code removed, and no longer require command line curl.
Now lets see if we can remove duplicated code in curl iteself and also
implement range support.
---
zypp.conf | 25 ++++
zypp/ZConfig.cc | 38 ++++++-
zypp/ZConfig.h | 23 ++++
zypp/media/MediaAccess.cc | 11 +--
zypp/media/MediaAccess.h | 2 +-
zypp/media/MediaAria2c.cc | 269 +++++----------------------------------
zypp/media/MediaAria2c.h | 3 +-
zypp/media/TransferSettings.cc | 50 ++++++++
zypp/media/TransferSettings.h | 50 +++++++-
9 files changed, 219 insertions(+), 252 deletions(-)
diff --git a/zypp.conf b/zypp.conf
index 0e089e0..8812e8f 100644
--- a/zypp.conf
+++ b/zypp.conf
@@ -120,6 +120,31 @@
##
# repo.refresh.delay = 10
+##
+## Maximum number of concurrent connections to use per transfer
+## This setting is only used if more than one is possible
+## Setting it to a reasonable number avoids flooding servers
+##
+# download.max_concurrent_connections = 2
+
+##
+## Sets the minimum download speed (bytes per second)
+## until the connection is dropped
+## This can be useful to prevent security attacks on hosts by
+## providing updates at very low speeds.
+##
+## 0 means no limit
+##
+# download.min_download_speed = 0
+
+## Maximum download speed (bytes per second)
+## 0 means no limit
+# download.max_download_speed = 0
+
+## Number of tries per download which will be
+## done without user interaction
+## 0 means no limit (use with caution)
+# download.max_silent_tries = 5
##
## Whether to consider using a .delta.rpm when downloading a package
diff --git a/zypp/ZConfig.cc b/zypp/ZConfig.cc
index 816b5fc..33b13f5 100644
--- a/zypp/ZConfig.cc
+++ b/zypp/ZConfig.cc
@@ -154,6 +154,10 @@ namespace zypp
, repo_refresh_delay ( 10 )
, download_use_deltarpm ( true )
, download_use_deltarpm_always ( false )
+ , download_max_concurrent_connections(2)
+ , download_min_download_speed(0)
+ , download_max_download_speed(0)
+ , download_max_silent_tries(5)
, solver_onlyRequires ( false )
, apply_locks_file ( true )
@@ -240,6 +244,22 @@ namespace zypp
{
download_use_deltarpm_always = str::strToBool( value, download_use_deltarpm_always );
}
+ else if ( entry == "download.max_concurrent_connections" )
+ {
+ str::strtonum(value, download_max_concurrent_connections);
+ }
+ else if ( entry == "download.min_download_speed" )
+ {
+ str::strtonum(value, download_min_download_speed);
+ }
+ else if ( entry == "download.max_download_speed" )
+ {
+ str::strtonum(value, download_max_download_speed);
+ }
+ else if ( entry == "download.max_silent_tries" )
+ {
+ str::strtonum(value, download_max_silent_tries);
+ }
else if ( entry == "vendordir" )
{
cfg_vendor_path = Pathname(value);
@@ -357,6 +377,11 @@ namespace zypp
bool download_use_deltarpm;
bool download_use_deltarpm_always;
+ int download_max_concurrent_connections;
+ int download_min_download_speed;
+ int download_max_download_speed;
+ int download_max_silent_tries;
+
bool solver_onlyRequires;
Pathname solver_checkSystemFile;
@@ -540,13 +565,24 @@ namespace zypp
bool ZConfig::download_use_deltarpm_always() const
{ return download_use_deltarpm() && _pimpl->download_use_deltarpm_always; }
+ long ZConfig::download_max_concurrent_connections() const
+ { return _pimpl->download_max_concurrent_connections; }
+
+ long ZConfig::download_min_download_speed() const
+ { return _pimpl->download_min_download_speed; }
+
+ long ZConfig::download_max_download_speed() const
+ { return _pimpl->download_max_download_speed; }
+
+ long ZConfig::download_max_silent_tries() const
+ { return _pimpl->download_max_silent_tries; }
+
bool ZConfig::solver_onlyRequires() const
{ return _pimpl->solver_onlyRequires; }
Pathname ZConfig::solver_checkSystemFile() const
{ return _pimpl->solver_checkSystemFile; }
-
std::set<IdString> ZConfig::multiversion() const
{ return _pimpl->multiversion; }
diff --git a/zypp/ZConfig.h b/zypp/ZConfig.h
index 9052ae9..9b73393 100644
--- a/zypp/ZConfig.h
+++ b/zypp/ZConfig.h
@@ -56,6 +56,7 @@ namespace zypp
class ZConfig : private base::NonCopyable
{
public:
+
/** Singleton ctor */
static ZConfig & instance();
@@ -153,6 +154,28 @@ namespace zypp
*/
unsigned repo_refresh_delay() const;
+ /**
+ * Maximum number of concurrent connections for a single transfer
+ */
+ long download_max_concurrent_connections() const;
+
+ /**
+ * Minimum download speed (bytes per second)
+ * until the connection is dropped
+ */
+ long download_min_download_speed() const;
+
+ /**
+ * Maximum download speed (bytes per second)
+ */
+ long download_max_download_speed() const;
+
+ /**
+ * Maximum silent tries
+ */
+ long download_max_silent_tries() const;
+
+
/** Whether to consider using a deltarpm when downloading a package.
* Config option <tt>download.use_deltarpm (true)</tt>
*/
diff --git a/zypp/media/MediaAccess.cc b/zypp/media/MediaAccess.cc
index 1030222..e429727 100644
--- a/zypp/media/MediaAccess.cc
+++ b/zypp/media/MediaAccess.cc
@@ -321,17 +321,8 @@ MediaAccess::release( const std::string & ejectDev )
// filename is interpreted relative to the attached url
// and a path prefix is preserved to destination
void
-MediaAccess::provideFile( const Pathname & filename, bool cached, bool checkonly) const
+MediaAccess::provideFile( const Pathname & filename ) const
{
- if ( cached ) {
- PathInfo pi( localPath( filename ) );
- if ( pi.isExist() )
- return;
- }
-
- if(checkonly)
- ZYPP_THROW(MediaFileNotFoundException(url(), filename));
-
if ( !_handler ) {
ZYPP_THROW(MediaNotOpenException("provideFile(" + filename.asString() + ")"));
}
diff --git a/zypp/media/MediaAccess.h b/zypp/media/MediaAccess.h
index 48dcd0d..8aa60cd 100644
--- a/zypp/media/MediaAccess.h
+++ b/zypp/media/MediaAccess.h
@@ -243,7 +243,7 @@ namespace zypp {
* \throws MediaException
*
**/
- void provideFile( const Pathname & filename, bool cached = false, bool checkonly = false ) const;
+ void provideFile( const Pathname & filename ) const;
/**
* Remove filename below attach point IFF handler downloads files
diff --git a/zypp/media/MediaAria2c.cc b/zypp/media/MediaAria2c.cc
index 8490a83..e9d04e4 100644
--- a/zypp/media/MediaAria2c.cc
+++ b/zypp/media/MediaAria2c.cc
@@ -26,10 +26,12 @@
#include "zypp/Target.h"
#include "zypp/ZYppFactory.h"
+#include "zypp/media/TransferProgram.h"
#include "zypp/media/MediaAria2c.h"
#include "zypp/media/proxyinfo/ProxyInfos.h"
#include "zypp/media/ProxyInfo.h"
#include "zypp/media/MediaUserAuth.h"
+#include "zypp/media/MediaCurl.h"
#include "zypp/thread/Once.h"
#include <cstdlib>
#include <sys/types.h>
@@ -169,12 +171,28 @@ void fillAriaCmdLine( const Pathname &ariapath,
args.push_back("--follow-metalink=mem");
args.push_back("--check-integrity=true");
- // only present in recent aria
- if ( Edition(ariaver) >= Edition("1.20") )
- args.push_back( "--use-head=false");
+ // only present in recent aria lets find out the aria version
+ vector<string> fields;
+ // "aria2c version x.x"
+ str::split( ariaver, std::back_inserter(fields));
+ if ( fields.size() == 3 )
+ {
+ if ( Edition(fields[2]) >= Edition("1.1.2") )
+ args.push_back( "--use-head=false");
+ }
+
+ if ( s.maxDownloadSpeed() > 0 )
+ args.push_back(str::form("--max-download-limit=%ld", s.maxDownloadSpeed()));
+ if ( s.minDownloadSpeed() > 0 )
+ args.push_back(str::form("--lowest-speed-limit=%ld", s.minDownloadSpeed()));
+ args.push_back(str::form("--max-tries=%ld", s.maxSilentTries()));
+
+ if ( Edition(fields[2]) < Edition("1.2.0") )
+ WAR << "aria2c is older than 1.2.0, some features may be disabled" << endl;
+
// TODO make this one configurable
- args.push_back( "--max-concurrent-downloads=2");
+ args.push_back(str::form("--max-concurrent-downloads=%ld", s.maxConcurrentConnections()));
// add the anonymous id.
for ( TransferSettings::Headers::const_iterator it = s.headersBegin();
@@ -232,74 +250,6 @@ void fillAriaCmdLine( const Pathname &ariapath,
args.push_back(url.asString().c_str());
}
-/**
- * comannd line for curl.
- * The argument list gets passed as reference
- * and it is filled.
- */
-void fillCurlCmdLine( const Pathname &curlpath,
- const TransferSettings &s,
- const Url &url,
- ExternalProgram::Arguments &args )
-{
- args.push_back(curlpath.c_str());
- // only do a head request
- args.push_back("-I");
- args.push_back("-A"); args.push_back(s.userAgentString());
-
- // headers.
- for ( TransferSettings::Headers::const_iterator it = s.headersBegin();
- it != s.headersEnd();
- ++it )
- {
- args.push_back("-H");
- args.push_back(it->c_str());
- }
-
- args.push_back("--connect-timeout");
- args.push_back(str::numstring(s.timeout()));
-
- if ( s.username().empty() )
- {
- if ( url.getScheme() == "ftp" )
- {
- string id = "yast2:";
- id += VERSION;
- args.push_back("--user");
- args.push_back(id);
- DBG << "Anonymous FTP identification: '" << id << "'" << endl;
- }
- }
- else
- {
- string userpass = s.username();
-
- if ( s.password().size() )
- userpass += (":" + s.password());
- args.push_back("--user");
- args.push_back(userpass);
- }
-
- if ( s.proxyEnabled() )
- {
- args.push_back("--proxy");
- args.push_back(s.proxy());
- if ( ! s.proxyUsername().empty() )
- {
- string userpass = s.proxyUsername();
-
- if ( s.proxyPassword().size() )
- userpass += (":" + s.proxyPassword());
- args.push_back("--proxy-user");
- args.push_back(userpass);
- }
- }
-
- args.push_back("--url");
- args.push_back(url.asString().c_str());
-}
-
-
static const char *const anonymousIdHeader()
{
// we need to add the release and identifier to the
@@ -355,12 +305,11 @@ const char *const MediaAria2c::agentString()
MediaAria2c::MediaAria2c( const Url & url_r,
const Pathname & attach_point_hint_r )
- : MediaHandler( url_r, attach_point_hint_r,
- "/", // urlpath at attachpoint
- true ) // does_download
+ : MediaCurl( url_r, attach_point_hint_r )
{
MIL << "MediaAria2c::MediaAria2c(" << url_r << ", " << attach_point_hint_r << ")" << endl;
+ /*
if( !attachPoint().empty())
{
PathInfo ainfo(attachPoint());
@@ -380,6 +329,7 @@ MediaAria2c::MediaAria2c( const Url & url_r,
if( atemp != NULL)
::free(atemp);
}
+ */
//At this point, we initialize aria2c path
_aria2cPath = Pathname( whereisAria2c().asString() );
@@ -390,25 +340,8 @@ MediaAria2c::MediaAria2c( const Url & url_r,
void MediaAria2c::attachTo (bool next)
{
- // clear last arguments
- if ( next )
- ZYPP_THROW(MediaNotSupportedException(_url));
-
- if ( !_url.isValid() )
- ZYPP_THROW(MediaBadUrlException(_url));
-
- if( !isUseableAttachPoint(attachPoint()))
- {
- std::string mountpoint = createAttachPoint().asString();
-
- if( mountpoint.empty())
- ZYPP_THROW( MediaBadAttachPointException(url()));
-
- setAttachPoint( mountpoint, true);
- }
-
- disconnectFrom();
-
+ MediaCurl::attachTo(next);
+
_settings.setUserAgentString(agentString());
_settings.addHeader(anonymousIdHeader());
_settings.addHeader(distributionFlavorHeader());
@@ -427,25 +360,23 @@ void MediaAria2c::attachTo (bool next)
}
DBG << "Proxy: " << (_settings.proxy().empty() ? "-none-" : _settings.proxy()) << endl;
-
- MediaSourceRef media( new MediaSource(_url.getScheme(), _url.asString()));
- setMediaSource(media);
-
}
bool
MediaAria2c::checkAttachPoint(const Pathname &apoint) const
{
- return MediaHandler::checkAttachPoint( apoint, true, true);
+ return MediaCurl::checkAttachPoint( apoint );
}
void MediaAria2c::disconnectFrom()
{
+ MediaCurl::disconnectFrom();
+
}
void MediaAria2c::releaseFrom( const std::string & ejectDev )
{
- disconnect();
+ MediaCurl::releaseFrom(ejectDev);
}
static Url getFileUrl(const Url & url, const Pathname & filename)
@@ -573,147 +504,17 @@ void MediaAria2c::getFileCopy( const Pathname & filename , const Pathname & targ
bool MediaAria2c::getDoesFileExist( const Pathname & filename ) const
{
- bool retry = false;
- AuthData auth_data;
-
- do
- {
- try
- {
- return doGetDoesFileExist( filename );
- }
- // authentication problem, retry with proper authentication data
- catch (MediaUnauthorizedException & ex_r)
- {
- if(authenticate(ex_r.hint(), !retry))
- retry = true;
- else
- ZYPP_RETHROW(ex_r);
- }
- // unexpected exception
- catch (MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
- }
- while (retry);
-
- return false;
+ return MediaCurl::getDoesFileExist(filename);
}
bool MediaAria2c::doGetDoesFileExist( const Pathname & filename ) const
{
- DBG << filename.asString() << endl;
- callback::SendReport<DownloadProgressReport> report;
-
- Url fileurl(getFileUrl(_url, filename));
- bool retry = false;
-
- ExternalProgram::Arguments args;
-
- fillCurlCmdLine("/usr/bin/curl", _settings, fileurl, args);
-
- do
- {
- try
- {
- report->start(_url, fileurl.asString() );
-
- ExternalProgram curl(args, ExternalProgram::Stderr_To_Stdout);
- //Process response
- for(std::string curlResponse( curl.receiveLine());
- curlResponse.length();
- curlResponse = curl.receiveLine())
- {
-
- if ( str::contains(curlResponse, "401 Authorization Required") )
- {
- ZYPP_THROW(MediaUnauthorizedException(
- _url, "Login failed.", "Login failed", "auth hint"
- ));
- }
-
- if ( str::contains(curlResponse, "404 Not Found") )
- return false;
-
- if ( str::contains(curlResponse, "200 OK") )
- return true;
- }
-
- int code = curl.close();
-
- switch (code)
- {
- case 0: break;
- // connection problems
- return true;
- case 1:
- case 2:
- case 3:
- case 7:
- default:
- ZYPP_THROW(MediaException(_url.asString()));
- }
-
-
- report->finish( _url , zypp::media::DownloadProgressReport::NO_ERROR, "");
- retry = false;
- }
- // retry with proper authentication data
- catch (MediaUnauthorizedException & ex_r)
- {
- if(authenticate(ex_r.hint(), !retry))
- retry = true;
- else
- {
- report->finish(fileurl, zypp::media::DownloadProgressReport::ACCESS_DENIED, ex_r.asUserHistory());
- ZYPP_RETHROW(ex_r);
- }
-
- }
- // unexpected exception
- catch (MediaException & excpt_r)
- {
- // FIXME: error number fix
- report->finish(fileurl, zypp::media::DownloadProgressReport::ERROR, excpt_r.asUserHistory());
- ZYPP_RETHROW(excpt_r);
- }
- }
- while (retry);
-
- report->finish(fileurl, zypp::media::DownloadProgressReport::NO_ERROR, "");
- return true;
+ return MediaCurl::doGetDoesFileExist(filename);
}
-
+
void MediaAria2c::getDir( const Pathname & dirname, bool recurse_r ) const
{
- filesystem::DirContent content;
- getDirInfo( content, dirname, /*dots*/false );
-
- for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
- Pathname filename = dirname + it->name;
- int res = 0;
-
- switch ( it->type ) {
- case filesystem::FT_NOT_AVAIL: // old directory.yast contains no typeinfo at all
- case filesystem::FT_FILE:
- getFile( filename );
- break;
- case filesystem::FT_DIR: // newer directory.yast contain at least directory info
- if ( recurse_r ) {
- getDir( filename, recurse_r );
- } else {
- res = assert_dir( localPath( filename ) );
- if ( res ) {
- WAR << "Ignore error (" << res << ") on creating local directory '" << localPath( filename ) << "'" << endl;
- }
- }
- break;
- default:
- // don't provide devices, sockets, etc.
- break;
- }
- }
+ MediaCurl::getDir(dirname, recurse_r);
}
bool MediaAria2c::authenticate(const std::string & availAuthTypes, bool firstTry) const
diff --git a/zypp/media/MediaAria2c.h b/zypp/media/MediaAria2c.h
index 9d58909..33d49f7 100644
--- a/zypp/media/MediaAria2c.h
+++ b/zypp/media/MediaAria2c.h
@@ -13,6 +13,7 @@
#define ZYPP_MEDIA_MEDIAARIA2C_H
#include "zypp/media/MediaHandler.h"
+#include "zypp/media/MediaCurl.h"
#include "zypp/media/TransferSettings.h"
#include "zypp/ZYppCallbacks.h"
@@ -27,7 +28,7 @@ namespace zypp {
*
* @see MediaHandler
**/
-class MediaAria2c : public MediaHandler {
+class MediaAria2c : public MediaCurl {
public:
/**
diff --git a/zypp/media/TransferSettings.cc b/zypp/media/TransferSettings.cc
index e50a3a5..b206d1b 100644
--- a/zypp/media/TransferSettings.cc
+++ b/zypp/media/TransferSettings.cc
@@ -9,6 +9,7 @@
#include "zypp/base/NonCopyable.h"
#include "zypp/ExternalProgram.h"
#include "zypp/media/TransferSettings.h"
+#include "zypp/ZConfig.h"
using namespace std;
@@ -27,6 +28,10 @@ public:
: _useproxy(false)
, _timeout(0)
, _connect_timeout(0)
+ , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections())
+ , _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
+ , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
+ , _maxSilentTries(ZConfig::instance().download_max_silent_tries())
{}
virtual ~Impl()
@@ -58,6 +63,11 @@ public:
long _connect_timeout;
Url _url;
Pathname _targetdir;
+
+ long _maxConcurrentConnections;
+ long _minDownloadSpeed;
+ long _maxDownloadSpeed;
+ long _maxSilentTries;
};
TransferSettings::TransferSettings()
@@ -171,6 +181,46 @@ long TransferSettings::connectTimeout() const
return _impl->_connect_timeout;
}
+long TransferSettings::maxConcurrentConnections() const
+{
+ return _impl->_maxConcurrentConnections;
+}
+
+void TransferSettings::setMaxConcurrentConnections(long v)
+{
+ _impl->_maxConcurrentConnections = v;
+}
+
+long TransferSettings::minDownloadSpeed() const
+{
+ return _impl->_minDownloadSpeed;
+}
+
+void TransferSettings::setMinDownloadSpeed(long v)
+{
+ _impl->_minDownloadSpeed = v;
+}
+
+long TransferSettings::maxDownloadSpeed() const
+{
+ return _impl->_maxDownloadSpeed;
+}
+
+void TransferSettings::setMaxDownloadSpeed(long v)
+{
+ _impl->_maxDownloadSpeed = v;
+}
+
+long TransferSettings::maxSilentTries() const
+{
+ return _impl->_maxSilentTries;
+}
+
+void TransferSettings::setMaxSilentTries(long v)
+{
+ _impl->_maxSilentTries = v;
+}
+
} // ns media
} // ns zypp
diff --git a/zypp/media/TransferSettings.h b/zypp/media/TransferSettings.h
index 3a513f0..1491bb7 100644
--- a/zypp/media/TransferSettings.h
+++ b/zypp/media/TransferSettings.h
@@ -1,6 +1,6 @@
-#ifndef TRANSFER_PROGRAM_H_
-#define TRANSFER_PROGRAM_H_
+#ifndef TRANSFER_SETTINGS_H_
+#define TRANSFER_SETTINGS_H_
#include <string>
#include <vector>
@@ -15,9 +15,7 @@ namespace media
{
/**
- * Easy access to the transfer command line program no matter
- * which one it is
- *
+ * Holds transfer setting
*/
class TransferSettings
{
@@ -140,6 +138,48 @@ public:
*/
long timeout() const;
+ /**
+ * Maximum number of concurrent connections for a single transfer
+ */
+ long maxConcurrentConnections() const;
+
+ /**
+ * Set maximum number of concurrent connections for a single transfer
+ */
+ void setMaxConcurrentConnections(long v);
+
+ /**
+ * Minimum download speed (bytes per second)
+ * until the connection is dropped
+ */
+ long minDownloadSpeed() const;
+
+ /**
+ * Set minimum download speed (bytes per second)
+ * until the connection is dropped
+ */
+ void setMinDownloadSpeed(long v);
+
+ /**
+ * Maximum download speed (bytes per second)
+ */
+ long maxDownloadSpeed() const;
+
+ /**
+ * Set max download speed (bytes per second)
+ */
+ void setMaxDownloadSpeed(long v);
+
+ /**
+ * Maximum silent retries
+ */
+ long maxSilentTries() const;
+
+ /**
+ * Set maximum silent retries
+ */
+ void setMaxSilentTries(long v);
+
protected:
class Impl;
RWCOW_pointer<Impl> _impl;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
ref: refs/heads/master
commit 45e04016d4f622104a37831c3d69c18d95905d2f
Author: Duncan Mac-Vicar P <dmacvicar(a)suse.de>
Date: Fri Feb 20 16:40:27 2009 +0100
changes
---
package/libzypp.changes | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/package/libzypp.changes b/package/libzypp.changes
index dabc23e..8a0df32 100644
--- a/package/libzypp.changes
+++ b/package/libzypp.changes
@@ -1,4 +1,12 @@
-------------------------------------------------------------------
+Fri Feb 20 16:28:19 CET 2009 - dmacvicar(a)suse.de
+
+- MediaAria2c: allow disabling aria2 using ZYPP_ARIA2C=0.
+ Various improvements including file existence checking
+ Disable HEAD request if aria2c >= 1.20
+ Restrict max connections to 2 for now.
+
+-------------------------------------------------------------------
Wed Feb 18 15:51:38 CET 2009 - ma(a)suse.de
- Neither lose packages with empty name, nor SEGV when processing them. (bnc #470011)
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <libzypp> master : merge poeml suggested changes, make sure we have the right aria version
by Duncan Mac-Vicar P 20 Feb '09
by Duncan Mac-Vicar P 20 Feb '09
20 Feb '09
ref: refs/heads/master
commit 9654af34ed0645cf2eecc11719838beff65995e9
Author: Duncan Mac-Vicar P <dmacvicar(a)suse.de>
Date: Fri Feb 20 16:27:54 2009 +0100
merge poeml suggested changes, make sure we have the right aria version
---
zypp/media/MediaAria2c.cc | 11 ++++++++++-
zypp/media/MediaAria2c.h | 5 -----
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/zypp/media/MediaAria2c.cc b/zypp/media/MediaAria2c.cc
index 5f34f2c..8490a83 100644
--- a/zypp/media/MediaAria2c.cc
+++ b/zypp/media/MediaAria2c.cc
@@ -22,6 +22,7 @@
#include "zypp/base/Gettext.h"
#include "zypp/ZYppCallbacks.h"
+#include "zypp/Edition.h"
#include "zypp/Target.h"
#include "zypp/ZYppFactory.h"
@@ -156,6 +157,7 @@ void fillSettingsSystemProxy( const Url&url, TransferSettings &s )
* and it is filled.
*/
void fillAriaCmdLine( const Pathname &ariapath,
+ const string &ariaver,
const TransferSettings &s,
const Url &url,
const Pathname &destination,
@@ -167,6 +169,13 @@ void fillAriaCmdLine( const Pathname &ariapath,
args.push_back("--follow-metalink=mem");
args.push_back("--check-integrity=true");
+ // only present in recent aria
+ if ( Edition(ariaver) >= Edition("1.20") )
+ args.push_back( "--use-head=false");
+
+ // TODO make this one configurable
+ args.push_back( "--max-concurrent-downloads=2");
+
// add the anonymous id.
for ( TransferSettings::Headers::const_iterator it = s.headersBegin();
it != s.headersEnd();
@@ -484,7 +493,7 @@ void MediaAria2c::getFileCopy( const Pathname & filename , const Pathname & targ
ExternalProgram::Arguments args;
- fillAriaCmdLine(_aria2cPath, _settings, fileurl, target.dirname(), args);
+ fillAriaCmdLine(_aria2cPath, _aria2cVersion, _settings, fileurl, target.dirname(), args);
do
{
diff --git a/zypp/media/MediaAria2c.h b/zypp/media/MediaAria2c.h
index 1020ea5..9d58909 100644
--- a/zypp/media/MediaAria2c.h
+++ b/zypp/media/MediaAria2c.h
@@ -95,13 +95,8 @@ class MediaAria2c : public MediaHandler {
bool authenticate(const std::string & availAuthTypes, bool firstTry) const;
- mutable std::string _userpwd;
- std::string _proxy;
- std::string _proxyuserpwd;
std::string _currentCookieFile;
std::string _ca_path;
- long _xfer_timeout;
-
static Pathname _cookieFile;
/** Aria2c path */
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
20 Feb '09
ref: refs/heads/master
commit 2ec97ca1930673f6dbf424678024393e349fb9b9
Author: Michael Andres <ma(a)suse.de>
Date: Fri Feb 20 14:58:45 2009 +0100
fix outdated python examples
---
examples/python/callbacks.py | 44 -------------------------
examples/python/exception.py | 12 +------
examples/python/install_updates_dryrun.py | 42 +++++++++++-------------
examples/python/list_available_resolvables.py | 25 --------------
examples/python/list_installed_resolvables.py | 14 --------
examples/python/list_target_resolvables.py | 25 --------------
examples/python/list_updates.py | 36 --------------------
7 files changed, 21 insertions(+), 177 deletions(-)
diff --git a/examples/python/callbacks.py b/examples/python/callbacks.py
deleted file mode 100755
index 89149de..0000000
--- a/examples/python/callbacks.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#! /usr/bin/python
-import zypp
-
-# ---------------------------------------------------------
-
-def myProgress( val ):
- print "myProgress %d" % val
- return True
-
-rec = zypp.ScanRpmDbReceive()
-rec.set_pymethod( myProgress )
-
-# ---------------------------------------------------------
-
-Z = zypp.ZYppFactory_instance().getZYpp()
-
-if True:
- Z.initializeTarget( zypp.Pathname("/Local/ROOT") )
- Z.addResolvables( Z.target().resolvables(), True );
-
-if False:
- repoManager = zypp.RepoManager()
- repos = repoManager.knownRepositories()
- for repo in repos:
- if not repo.enabled():
- continue
- if not repoManager.isCached( repo ):
- repoManager.buildCache( repo )
- Z.addResolvables( repoManager.createFromCache( repo ).resolvables() )
-
-print "Items: %d" % ( Z.pool().size() )
-
-if False:
- for item in Z.pool():
- if item.status().isInstalled():
- t = "i"
- else:
- t = "*"
- print "%s %s:%s-%s.%s\t(%s)" % ( t,
- item.resolvable().kind(),
- item.resolvable().name(),
- item.resolvable().edition(),
- item.resolvable().arch(),
- item.resolvable().repository().info().alias() )
diff --git a/examples/python/exception.py b/examples/python/exception.py
index 4d65b64..9b7e6ec 100755
--- a/examples/python/exception.py
+++ b/examples/python/exception.py
@@ -2,16 +2,8 @@
from zypp import TmpDir, RepoManagerOptions, RepoManager, RepoInfo, Url
-tmp_cache_path = TmpDir()
-tmp_raw_cache_path = TmpDir()
-tmp_known_repos_path = TmpDir()
-
-opts = RepoManagerOptions()
-opts.repoCachePath = tmp_cache_path.path()
-opts.repoRawCachePath = tmp_raw_cache_path.path()
-opts.knownReposPath = tmp_known_repos_path.path()
-
-repo_manager = RepoManager(opts)
+tmp_root=TmpDir()
+repo_manager = RepoManager(RepoManagerOptions(tmp_root.path()))
repo_info = RepoInfo()
diff --git a/examples/python/install_updates_dryrun.py b/examples/python/install_updates_dryrun.py
index f3fb10c..05e7c72 100755
--- a/examples/python/install_updates_dryrun.py
+++ b/examples/python/install_updates_dryrun.py
@@ -8,50 +8,46 @@ except ImportError:
print 'Dummy Import Error: Unable to import zypp bindings'
print 'Reading repositories...'
-
Z = zypp.ZYppFactory_instance().getZYpp()
-
Z.initializeTarget( zypp.Pathname("/") )
-Z.addResolvables( Z.target().resolvables(), True )
+Z.target().load();
repoManager = zypp.RepoManager()
repos = repoManager.knownRepositories()
for repo in repos:
- if repo.enabled() and repo.autorefresh():
- try:
- repoManager.refreshMetadata(repo, zypp.RepoManager.RefreshIfNeeded) # or RefreshIfNeeded == 0
- except:
- repoManager.buildCache( repo )
-
- Z.addResolvables( repoManager.createFromCache( repo ).resolvables())
-
-Z.applyLocks()
-Z.resolver().establishPool();
+ if not repo.enabled():
+ continue
+ if not repoManager.isCached( repo ):
+ repoManager.buildCache( repo )
+ repoManager.loadFromCache( repo );
+print "Items: %d" % ( Z.pool().size() )
#
# Does not to check and apply updates for the update stack first.
#
-print 'List Upadtes:'
-for item in Z.pool().byKindIterator(zypp.KindOfPatch()):
- if item.status().isInstalled():
- continue
- if item.status().isNeeded():
- if not item.status().setTransact( True, zypp.ResStatus.USER ):
- raise "Error set transact: %s" % item
- resolvable = zypp.asKindPatch( item )
- print '%s | %s-%s | %s | %s' % (resolvable.repository().info().alias(), resolvable.name(), resolvable.edition(), resolvable.category(), item.status() )
+Z.resolver().resolvePool()
+
+for item in Z.pool():
+ if not zypp.isKindPatch( item ):
+ continue
+ if item.isBroken():
+ if not item.status().setTransact( True, zypp.ResStatus.USER ):
+ raise "Error set transact: %s" % item
+ resolvable = zypp.asKindPatch( item )
+ print '%s | %s-%s | %s | %s' % (resolvable.repoInfo().alias(), resolvable.name(), resolvable.edition(), resolvable.category(), item.status() )
if not Z.resolver().resolvePool():
raise "Solver Error"
for item in Z.pool():
if item.status().transacts():
- print item
+ print '%s | %s-%s | %s' % (item.repoInfo().alias(), item.name(), item.edition(), item.status() )
#
# dryRun!
#
+
policy = zypp.ZYppCommitPolicy()
policy.dryRun( True )
policy.syncPoolAfterCommit( False )
diff --git a/examples/python/list_available_resolvables.py b/examples/python/list_available_resolvables.py
deleted file mode 100755
index 39f5f38..0000000
--- a/examples/python/list_available_resolvables.py
+++ /dev/null
@@ -1,25 +0,0 @@
-#! /usr/bin/python
-import zypp
-
-Z = zypp.ZYppFactory_instance().getZYpp()
-
-repoManager = zypp.RepoManager()
-repos = repoManager.knownRepositories()
-
-for repo in repos:
- if not repo.enabled():
- continue
- if not repoManager.isCached( repo ):
- repoManager.buildCache( repo )
-
- Z.addResolvables( repoManager.createFromCache( repo ).resolvables() )
-
-
-print "Available items: %d" % ( Z.pool().size() )
-
-for item in Z.pool():
- print "* %s:%s-%s.%s\t(%s)" % ( item.resolvable().kind(),
- item.resolvable().name(),
- item.resolvable().edition(),
- item.resolvable().arch(),
- item.resolvable().repository().info().alias() )
diff --git a/examples/python/list_installed_resolvables.py b/examples/python/list_installed_resolvables.py
deleted file mode 100755
index f4ded7e..0000000
--- a/examples/python/list_installed_resolvables.py
+++ /dev/null
@@ -1,14 +0,0 @@
-#! /usr/bin/python
-import zypp
-
-Z = zypp.ZYppFactory_instance().getZYpp()
-Z.initializeTarget( zypp.Pathname("/") )
-Z.addResolvables( Z.target().resolvables(), True );
-
-print "Installed items: %d" % ( Z.pool().size() )
-
-for item in Z.pool():
- print "i %s:%s-%s.%s" % ( item.resolvable().kind(),
- item.resolvable().name(),
- item.resolvable().edition(),
- item.resolvable().arch() )
diff --git a/examples/python/list_target_resolvables.py b/examples/python/list_target_resolvables.py
deleted file mode 100755
index 27d9b6f..0000000
--- a/examples/python/list_target_resolvables.py
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/python
-
-from zypp import ZYppFactory, Pathname, Dep
-
-z = ZYppFactory.instance().getZYpp()
-print z
-
-z.initializeTarget(Pathname("/"))
-
-r = z.target().resolvables()
-print r
-
-# TODO: display resolvables
-
-p = r.haha()
-print p
-print p.name()
-print p.summary()
-
-d = p.dep(Dep.PROVIDES)
-print d
-
-x = d.haha()
-print x
-
diff --git a/examples/python/list_updates.py b/examples/python/list_updates.py
deleted file mode 100755
index 3f899d4..0000000
--- a/examples/python/list_updates.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#! /usr/bin/python
-
-import os, sys, types, string, re
-
-try:
- import zypp
-except ImportError:
- print 'Dummy Import Error: Unable to import zypp bindings'
-
-print 'Reading repositories...'
-
-Z = zypp.ZYppFactory_instance().getZYpp()
-
-Z.initializeTarget( zypp.Pathname("/") )
-Z.addResolvables( Z.target().resolvables(), True )
-
-repoManager = zypp.RepoManager()
-repos = repoManager.knownRepositories()
-
-for repo in repos:
- if repo.enabled() and repo.autorefresh():
- try:
- repoManager.refreshMetadata(repo, zypp.RepoManager.RefreshIfNeeded) # or RefreshIfNeeded == 0
- except:
- repoManager.buildCache( repo )
-
- Z.addResolvables( repoManager.createFromCache( repo ).resolvables())
-
-Z.applyLocks()
-Z.resolver().establishPool();
-
-print 'List Updates:'
-for item in Z.pool().byKindIterator(zypp.KindOfPatch()):
- if item.status().isNeeded():
- resolvable = zypp.asKindPatch( item )
- print '%s | %s-%s | %s | %s' % (resolvable.repository().info().alias(), resolvable.name(), resolvable.edition(), resolvable.category(), item.status() )
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <libzypp-bindings> SuSE-Code-11-Branch : fix outdated python examples
by Michael Andres 20 Feb '09
by Michael Andres 20 Feb '09
20 Feb '09
ref: refs/heads/SuSE-Code-11-Branch
commit 282e72d7b5f1560dd8444e2405cdab36b4271c9a
Author: Michael Andres <ma(a)suse.de>
Date: Fri Feb 20 14:58:45 2009 +0100
fix outdated python examples
---
examples/python/callbacks.py | 44 -------------------------
examples/python/exception.py | 12 +------
examples/python/install_updates_dryrun.py | 42 +++++++++++-------------
examples/python/list_available_resolvables.py | 25 --------------
examples/python/list_installed_resolvables.py | 14 --------
examples/python/list_target_resolvables.py | 25 --------------
examples/python/list_updates.py | 36 --------------------
7 files changed, 21 insertions(+), 177 deletions(-)
diff --git a/examples/python/callbacks.py b/examples/python/callbacks.py
deleted file mode 100755
index 89149de..0000000
--- a/examples/python/callbacks.py
+++ /dev/null
@@ -1,44 +0,0 @@
-#! /usr/bin/python
-import zypp
-
-# ---------------------------------------------------------
-
-def myProgress( val ):
- print "myProgress %d" % val
- return True
-
-rec = zypp.ScanRpmDbReceive()
-rec.set_pymethod( myProgress )
-
-# ---------------------------------------------------------
-
-Z = zypp.ZYppFactory_instance().getZYpp()
-
-if True:
- Z.initializeTarget( zypp.Pathname("/Local/ROOT") )
- Z.addResolvables( Z.target().resolvables(), True );
-
-if False:
- repoManager = zypp.RepoManager()
- repos = repoManager.knownRepositories()
- for repo in repos:
- if not repo.enabled():
- continue
- if not repoManager.isCached( repo ):
- repoManager.buildCache( repo )
- Z.addResolvables( repoManager.createFromCache( repo ).resolvables() )
-
-print "Items: %d" % ( Z.pool().size() )
-
-if False:
- for item in Z.pool():
- if item.status().isInstalled():
- t = "i"
- else:
- t = "*"
- print "%s %s:%s-%s.%s\t(%s)" % ( t,
- item.resolvable().kind(),
- item.resolvable().name(),
- item.resolvable().edition(),
- item.resolvable().arch(),
- item.resolvable().repository().info().alias() )
diff --git a/examples/python/exception.py b/examples/python/exception.py
index 4d65b64..9b7e6ec 100755
--- a/examples/python/exception.py
+++ b/examples/python/exception.py
@@ -2,16 +2,8 @@
from zypp import TmpDir, RepoManagerOptions, RepoManager, RepoInfo, Url
-tmp_cache_path = TmpDir()
-tmp_raw_cache_path = TmpDir()
-tmp_known_repos_path = TmpDir()
-
-opts = RepoManagerOptions()
-opts.repoCachePath = tmp_cache_path.path()
-opts.repoRawCachePath = tmp_raw_cache_path.path()
-opts.knownReposPath = tmp_known_repos_path.path()
-
-repo_manager = RepoManager(opts)
+tmp_root=TmpDir()
+repo_manager = RepoManager(RepoManagerOptions(tmp_root.path()))
repo_info = RepoInfo()
diff --git a/examples/python/install_updates_dryrun.py b/examples/python/install_updates_dryrun.py
index f3fb10c..05e7c72 100755
--- a/examples/python/install_updates_dryrun.py
+++ b/examples/python/install_updates_dryrun.py
@@ -8,50 +8,46 @@ except ImportError:
print 'Dummy Import Error: Unable to import zypp bindings'
print 'Reading repositories...'
-
Z = zypp.ZYppFactory_instance().getZYpp()
-
Z.initializeTarget( zypp.Pathname("/") )
-Z.addResolvables( Z.target().resolvables(), True )
+Z.target().load();
repoManager = zypp.RepoManager()
repos = repoManager.knownRepositories()
for repo in repos:
- if repo.enabled() and repo.autorefresh():
- try:
- repoManager.refreshMetadata(repo, zypp.RepoManager.RefreshIfNeeded) # or RefreshIfNeeded == 0
- except:
- repoManager.buildCache( repo )
-
- Z.addResolvables( repoManager.createFromCache( repo ).resolvables())
-
-Z.applyLocks()
-Z.resolver().establishPool();
+ if not repo.enabled():
+ continue
+ if not repoManager.isCached( repo ):
+ repoManager.buildCache( repo )
+ repoManager.loadFromCache( repo );
+print "Items: %d" % ( Z.pool().size() )
#
# Does not to check and apply updates for the update stack first.
#
-print 'List Upadtes:'
-for item in Z.pool().byKindIterator(zypp.KindOfPatch()):
- if item.status().isInstalled():
- continue
- if item.status().isNeeded():
- if not item.status().setTransact( True, zypp.ResStatus.USER ):
- raise "Error set transact: %s" % item
- resolvable = zypp.asKindPatch( item )
- print '%s | %s-%s | %s | %s' % (resolvable.repository().info().alias(), resolvable.name(), resolvable.edition(), resolvable.category(), item.status() )
+Z.resolver().resolvePool()
+
+for item in Z.pool():
+ if not zypp.isKindPatch( item ):
+ continue
+ if item.isBroken():
+ if not item.status().setTransact( True, zypp.ResStatus.USER ):
+ raise "Error set transact: %s" % item
+ resolvable = zypp.asKindPatch( item )
+ print '%s | %s-%s | %s | %s' % (resolvable.repoInfo().alias(), resolvable.name(), resolvable.edition(), resolvable.category(), item.status() )
if not Z.resolver().resolvePool():
raise "Solver Error"
for item in Z.pool():
if item.status().transacts():
- print item
+ print '%s | %s-%s | %s' % (item.repoInfo().alias(), item.name(), item.edition(), item.status() )
#
# dryRun!
#
+
policy = zypp.ZYppCommitPolicy()
policy.dryRun( True )
policy.syncPoolAfterCommit( False )
diff --git a/examples/python/list_available_resolvables.py b/examples/python/list_available_resolvables.py
deleted file mode 100755
index 39f5f38..0000000
--- a/examples/python/list_available_resolvables.py
+++ /dev/null
@@ -1,25 +0,0 @@
-#! /usr/bin/python
-import zypp
-
-Z = zypp.ZYppFactory_instance().getZYpp()
-
-repoManager = zypp.RepoManager()
-repos = repoManager.knownRepositories()
-
-for repo in repos:
- if not repo.enabled():
- continue
- if not repoManager.isCached( repo ):
- repoManager.buildCache( repo )
-
- Z.addResolvables( repoManager.createFromCache( repo ).resolvables() )
-
-
-print "Available items: %d" % ( Z.pool().size() )
-
-for item in Z.pool():
- print "* %s:%s-%s.%s\t(%s)" % ( item.resolvable().kind(),
- item.resolvable().name(),
- item.resolvable().edition(),
- item.resolvable().arch(),
- item.resolvable().repository().info().alias() )
diff --git a/examples/python/list_installed_resolvables.py b/examples/python/list_installed_resolvables.py
deleted file mode 100755
index f4ded7e..0000000
--- a/examples/python/list_installed_resolvables.py
+++ /dev/null
@@ -1,14 +0,0 @@
-#! /usr/bin/python
-import zypp
-
-Z = zypp.ZYppFactory_instance().getZYpp()
-Z.initializeTarget( zypp.Pathname("/") )
-Z.addResolvables( Z.target().resolvables(), True );
-
-print "Installed items: %d" % ( Z.pool().size() )
-
-for item in Z.pool():
- print "i %s:%s-%s.%s" % ( item.resolvable().kind(),
- item.resolvable().name(),
- item.resolvable().edition(),
- item.resolvable().arch() )
diff --git a/examples/python/list_target_resolvables.py b/examples/python/list_target_resolvables.py
deleted file mode 100755
index 27d9b6f..0000000
--- a/examples/python/list_target_resolvables.py
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/python
-
-from zypp import ZYppFactory, Pathname, Dep
-
-z = ZYppFactory.instance().getZYpp()
-print z
-
-z.initializeTarget(Pathname("/"))
-
-r = z.target().resolvables()
-print r
-
-# TODO: display resolvables
-
-p = r.haha()
-print p
-print p.name()
-print p.summary()
-
-d = p.dep(Dep.PROVIDES)
-print d
-
-x = d.haha()
-print x
-
diff --git a/examples/python/list_updates.py b/examples/python/list_updates.py
deleted file mode 100755
index 3f899d4..0000000
--- a/examples/python/list_updates.py
+++ /dev/null
@@ -1,36 +0,0 @@
-#! /usr/bin/python
-
-import os, sys, types, string, re
-
-try:
- import zypp
-except ImportError:
- print 'Dummy Import Error: Unable to import zypp bindings'
-
-print 'Reading repositories...'
-
-Z = zypp.ZYppFactory_instance().getZYpp()
-
-Z.initializeTarget( zypp.Pathname("/") )
-Z.addResolvables( Z.target().resolvables(), True )
-
-repoManager = zypp.RepoManager()
-repos = repoManager.knownRepositories()
-
-for repo in repos:
- if repo.enabled() and repo.autorefresh():
- try:
- repoManager.refreshMetadata(repo, zypp.RepoManager.RefreshIfNeeded) # or RefreshIfNeeded == 0
- except:
- repoManager.buildCache( repo )
-
- Z.addResolvables( repoManager.createFromCache( repo ).resolvables())
-
-Z.applyLocks()
-Z.resolver().establishPool();
-
-print 'List Updates:'
-for item in Z.pool().byKindIterator(zypp.KindOfPatch()):
- if item.status().isNeeded():
- resolvable = zypp.asKindPatch( item )
- print '%s | %s-%s | %s | %s' % (resolvable.repository().info().alias(), resolvable.name(), resolvable.edition(), resolvable.category(), item.status() )
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <libzypp> master : - implement "does file exist" using curl command line in the aria backend
by Duncan Mac-Vicar P 20 Feb '09
by Duncan Mac-Vicar P 20 Feb '09
20 Feb '09
ref: refs/heads/master
commit f276f8fc3cf8a543466523b94c91b8cb1035556f
Author: Duncan Mac-Vicar P <dmacvicar(a)suse.de>
Date: Fri Feb 20 14:48:23 2009 +0100
- implement "does file exist" using curl command line in the aria backend
- fix testcases by using webserver class once per test
- switch tests back to mongoose embeded
PENDING:
- handling curl errors more granular
- enable aria backend by default, allow using ZYPP_ARIA2C=0 to disable
---
tests/lib/WebServer.cc | 19 +++++++++++++------
tests/zypp/Fetcher_test.cc | 30 ++++++------------------------
tests/zypp/MediaSetAccess_test.cc | 29 ++++++++++++++---------------
zypp/media/MediaAccess.cc | 24 +++++++++++++++++++++++-
zypp/media/MediaAria2c.cc | 16 +++++++++++++++-
5 files changed, 71 insertions(+), 47 deletions(-)
diff --git a/tests/lib/WebServer.cc b/tests/lib/WebServer.cc
index 15d9430..030c6f0 100644
--- a/tests/lib/WebServer.cc
+++ b/tests/lib/WebServer.cc
@@ -25,7 +25,7 @@ static inline string hostname()
return result;
}
-#define WEBRICK 1
+#define WEBRICK 0
class WebServer::Impl
{
@@ -88,7 +88,7 @@ public:
stringstream strlog(_log);
- string webrick_code = str::form("require 'webrick'; s = WEBrick::HTTPServer.new(:Port => %d, :DocumentRoot => '%s'); trap('INT'){ s.shutdown }; trap('SIGKILL') { s.shutdown }; s.start;", _port, _docroot.c_str());
+ string webrick_code = str::form("require \"webrick\"; s = WEBrick::HTTPServer.new(:Port => %d, :DocumentRoot => \"%s\"); trap(\"INT\"){ s.shutdown }; trap(\"SIGKILL\") { s.shutdown }; s.start;", _port, _docroot.c_str());
const char* argv[] =
{
@@ -163,10 +163,17 @@ public:
MIL << "Starting shttpd (mongoose)" << endl;
_log.clear();
_ctx = mg_start();
- if ( ! mg_set_option(_ctx, "ports", str::form("%d", _port).c_str()) )
- ZYPP_THROW(Exception("Failed to set port"));
+
+ int ret = 0;
+ ret = mg_set_option(_ctx, "ports", str::form("%d", _port).c_str());
+ if ( ret != 1 )
+ ZYPP_THROW(Exception(str::form("Failed to set port: %d", ret)));
- mg_set_option(_ctx, "root", _docroot.c_str());
+ MIL << "Setting root directory to : '" << _docroot << "'" << endl;
+ ret = mg_set_option(_ctx, "root", _docroot.c_str());
+ if ( ret != 1 )
+ ZYPP_THROW(Exception(str::form("Failed to set docroot: %d", ret)));
+
_stopped = false;
}
@@ -175,7 +182,7 @@ public:
return _port;
}
-
+
virtual string log() const
{
return _log;
diff --git a/tests/zypp/Fetcher_test.cc b/tests/zypp/Fetcher_test.cc
index c7af0a4..0adcb6f 100644
--- a/tests/zypp/Fetcher_test.cc
+++ b/tests/zypp/Fetcher_test.cc
@@ -320,14 +320,11 @@ BOOST_AUTO_TEST_CASE(enqueue_broken_content_noindex)
BOOST_AUTO_TEST_CASE(enqueuedir_http)
{
+ WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str(), 10001);
+ web.start();
+
// at this point the key is already trusted
{
- // add the key as trusted
- //getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
-
- WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str(), 10001);
- web.start();
-
MediaSetAccess media( web.url(), "/" );
Fetcher fetcher;
filesystem::TmpDir dest;
@@ -343,21 +340,10 @@ BOOST_AUTO_TEST_CASE(enqueuedir_http)
BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
-
- web.stop();
}
-}
-BOOST_AUTO_TEST_CASE(enqueuedir_http_broken)
-{
- // at this point the key is already trusted
+ // test broken tree
{
- // add the key as trusted
- //getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
-
- WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str() , 10001 );
- web.start();
-
MediaSetAccess media( web.url(), "/" );
Fetcher fetcher;
filesystem::TmpDir dest;
@@ -378,15 +364,11 @@ BOOST_AUTO_TEST_CASE(enqueuedir_http_broken)
BOOST_CHECK( ! PathInfo(dest.path() + "/complexdir-broken/subdir1/subdir1-file2.txt").isExist() );
fetcher.reset();
-
- web.stop();
-
- MIL << web.log();
-
}
+
+ web.stop();
}
-
BOOST_AUTO_TEST_SUITE_END();
// vim: set ts=2 sts=2 sw=2 ai et:
diff --git a/tests/zypp/MediaSetAccess_test.cc b/tests/zypp/MediaSetAccess_test.cc
index c8f1b26..7889010 100644
--- a/tests/zypp/MediaSetAccess_test.cc
+++ b/tests/zypp/MediaSetAccess_test.cc
@@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(msa_url_rewrite)
Url("http://ftp.opensuse.org/pub/opensuse/distribution/SL-OSS-factory/inst-source").asString());
}
-#define DATADIR (string("dir:") + string(TESTS_SRC_DIR) + string("/zypp/data/mediasetaccess"))
+#define DATADIR (Pathname(TESTS_SRC_DIR) / "/zypp/data/mediasetaccess")
/*
*
@@ -121,8 +121,7 @@ BOOST_AUTO_TEST_CASE(msa_url_rewrite)
*/
BOOST_AUTO_TEST_CASE(msa_provide_files_set)
{
- string urlstr = DATADIR + "/src1/cd1";
- Url url(urlstr);
+ Url url = (DATADIR + "/src1/cd1").asUrl();
MediaSetAccess setaccess(url);
Pathname file1 = setaccess.provideFile("/test.txt", 1);
@@ -140,8 +139,7 @@ BOOST_AUTO_TEST_CASE(msa_provide_files_set)
*/
BOOST_AUTO_TEST_CASE(msa_provide_files_set_verified)
{
- string urlstr = DATADIR + "/src1/cd1";
- Url url(urlstr);
+ Url url = (DATADIR + "/src1/cd1").asUrl();
MediaSetAccess setaccess(url);
setaccess.setVerifier(1, media::MediaVerifierRef(new SimpleVerifier("media1")));
@@ -166,8 +164,7 @@ BOOST_AUTO_TEST_CASE(msa_provide_files_set_verified)
*/
BOOST_AUTO_TEST_CASE(msa_provide_files_single)
{
- string urlstr = DATADIR + "/src2";
- Url url(urlstr);
+ Url url = (DATADIR + "/src2").asUrl();
MediaSetAccess setaccess(url);
setaccess.setVerifier(1, media::MediaVerifierRef(new SimpleVerifier("media")));
@@ -186,8 +183,8 @@ BOOST_AUTO_TEST_CASE(msa_provide_files_single)
*/
BOOST_AUTO_TEST_CASE(msa_provide_dir)
{
- string urlstr = DATADIR + "/src1/cd1";
- Url url(urlstr);
+ Url url = (DATADIR + "/src1/cd1").asUrl();
+
MediaSetAccess setaccess(url);
Pathname dir = setaccess.provideDir("/dir", false, 1);
@@ -217,8 +214,7 @@ BOOST_AUTO_TEST_CASE(msa_provide_dir)
*/
BOOST_AUTO_TEST_CASE(msa_provide_dirtree)
{
- string urlstr = DATADIR + "/src1/cd1";
- Url url(urlstr);
+ Url url = (DATADIR + "/src1/cd1").asUrl();
MediaSetAccess setaccess(url);
Pathname dir = setaccess.provideDir("/dir", true, 1);
@@ -238,7 +234,8 @@ BOOST_AUTO_TEST_CASE(msa_provide_dirtree)
*/
BOOST_AUTO_TEST_CASE(msa_provide_optional_file)
{
- MediaSetAccess setaccess(Url(DATADIR + "/src1/cd1"));
+ Url url = (DATADIR + "/src1/cd1").asUrl();
+ MediaSetAccess setaccess(url);
// must not throw
BOOST_CHECK(setaccess.provideOptionalFile("/foo", 1).empty() == true);
@@ -254,7 +251,8 @@ BOOST_AUTO_TEST_CASE(msa_provide_optional_file)
*/
BOOST_AUTO_TEST_CASE(msa_file_exist_local)
{
- MediaSetAccess setaccess(Url(DATADIR + "/src1/cd1"));
+ Url url = (DATADIR + "/src1/cd1").asUrl();
+ MediaSetAccess setaccess(url);
BOOST_CHECK(setaccess.doesFileExist("/test.txt"));
BOOST_CHECK(!setaccess.doesFileExist("/testBADNAME.txt"));
@@ -265,12 +263,13 @@ BOOST_AUTO_TEST_CASE(msa_file_exist_local)
*/
BOOST_AUTO_TEST_CASE(msa_file_exist_remote)
{
- WebServer web( Pathname(DATADIR) / "/src1/cd1", 10001 );
+ WebServer web( DATADIR / "/src1/cd1", 10002 );
web.start();
MediaSetAccess setaccess( web.url(), "/" );
- BOOST_CHECK(setaccess.doesFileExist("/test.txt"));
BOOST_CHECK(!setaccess.doesFileExist("/testBADNAME.txt"));
+ BOOST_CHECK(setaccess.doesFileExist("/test.txt"));
+
web.stop();
}
diff --git a/zypp/media/MediaAccess.cc b/zypp/media/MediaAccess.cc
index 85ac5ea..1030222 100644
--- a/zypp/media/MediaAccess.cc
+++ b/zypp/media/MediaAccess.cc
@@ -128,7 +128,29 @@ MediaAccess::open (const Url& url, const Pathname & preferred_attach_point)
else if (scheme == "cifs")
_handler = new MediaCIFS (url,preferred_attach_point);
else if (scheme == "ftp" || scheme == "http" || scheme == "https")
- _handler = new MediaAria2c (url,preferred_attach_point);
+ {
+ // Another good idea would be activate MediaAria2c handler via external var
+ bool use_aria = true;
+ const char *ariaenv = getenv( "ZYPP_ARIA2C" );
+ // if user disabled it manually
+ if ( ariaenv && ( strcmp(ariaenv, "0" ) == 0 ) )
+ {
+ WAR << "aria2c manually disabled. Falling back to curl";
+ use_aria = false;
+ }
+
+ // disable if it does not exist
+ if ( ! MediaAria2c::existsAria2cmd() )
+ {
+ WAR << "aria2c not found. Falling back to curl";
+ use_aria = false;
+ }
+
+ if ( use_aria )
+ _handler = new MediaAria2c (url,preferred_attach_point);
+ else
+ _handler = new MediaCurl (url,preferred_attach_point);
+ }
else
{
ZYPP_THROW(MediaUnsupportedUrlSchemeException(url));
diff --git a/zypp/media/MediaAria2c.cc b/zypp/media/MediaAria2c.cc
index a5de650..5f34f2c 100644
--- a/zypp/media/MediaAria2c.cc
+++ b/zypp/media/MediaAria2c.cc
@@ -628,11 +628,25 @@ bool MediaAria2c::doGetDoesFileExist( const Pathname & filename ) const
return false;
if ( str::contains(curlResponse, "200 OK") )
- return false;
+ return true;
}
int code = curl.close();
+ switch (code)
+ {
+ case 0: break;
+ // connection problems
+ return true;
+ case 1:
+ case 2:
+ case 3:
+ case 7:
+ default:
+ ZYPP_THROW(MediaException(_url.asString()));
+ }
+
+
report->finish( _url , zypp::media::DownloadProgressReport::NO_ERROR, "");
retry = false;
}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <libzypp> dmacvicar_aria : make TransferProgram actually a data transfer class to keep transfer
by Duncan Mac-Vicar P 18 Feb '09
by Duncan Mac-Vicar P 18 Feb '09
18 Feb '09
ref: refs/heads/dmacvicar_aria
commit 4f63cf8d0e70dfc345d61103f22e2a0f3e6e1fcc
Author: Duncan Mac-Vicar P <dmacvicar(a)suse.de>
Date: Wed Feb 18 18:33:24 2009 +0100
make TransferProgram actually a data transfer class to keep transfer
settings and share them across curl and aria.
Integrate for first time curl into aria
add a new test case for media set access doesFileExist (which does not
pass, because when it does, I am done :-) )
---
tests/zypp/MediaSetAccess_test.cc | 28 +++
zypp/CMakeLists.txt | 4 +-
zypp/media/MediaAria2c.cc | 466 ++++++++++++++++++++++++-------------
zypp/media/MediaAria2c.h | 3 +-
zypp/media/TransferProgram.cc | 206 ----------------
zypp/media/TransferProgram.h | 135 -----------
zypp/media/TransferSettings.cc | 176 ++++++++++++++
zypp/media/TransferSettings.h | 151 ++++++++++++
8 files changed, 658 insertions(+), 511 deletions(-)
diff --git a/tests/zypp/MediaSetAccess_test.cc b/tests/zypp/MediaSetAccess_test.cc
index 608ce3f..c8f1b26 100644
--- a/tests/zypp/MediaSetAccess_test.cc
+++ b/tests/zypp/MediaSetAccess_test.cc
@@ -7,6 +7,8 @@
#include "zypp/MediaSetAccess.h"
#include "zypp/Url.h"
+#include "WebServer.h"
+
using std::cout;
using std::endl;
using std::string;
@@ -247,4 +249,30 @@ BOOST_AUTO_TEST_CASE(msa_provide_optional_file)
//! \todo test provideOptionalFile with not desired media
}
+/*
+ * file exists local
+ */
+BOOST_AUTO_TEST_CASE(msa_file_exist_local)
+{
+ MediaSetAccess setaccess(Url(DATADIR + "/src1/cd1"));
+
+ BOOST_CHECK(setaccess.doesFileExist("/test.txt"));
+ BOOST_CHECK(!setaccess.doesFileExist("/testBADNAME.txt"));
+}
+
+/*
+ * file exists remote
+ */
+BOOST_AUTO_TEST_CASE(msa_file_exist_remote)
+{
+ WebServer web( Pathname(DATADIR) / "/src1/cd1", 10001 );
+ web.start();
+ MediaSetAccess setaccess( web.url(), "/" );
+
+ BOOST_CHECK(setaccess.doesFileExist("/test.txt"));
+ BOOST_CHECK(!setaccess.doesFileExist("/testBADNAME.txt"));
+ web.stop();
+}
+
+
// vim: set ts=2 sts=2 sw=2 ai et:
diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt
index 6eb2f37..7a7f27f 100644
--- a/zypp/CMakeLists.txt
+++ b/zypp/CMakeLists.txt
@@ -270,7 +270,7 @@ SET( zypp_media_SRCS
media/CredentialFileReader.cc
media/CredentialManager.cc
media/CurlConfig.cc
- media/TransferProgram.cc
+ media/TransferSettings.cc
)
SET( zypp_media_HEADERS
@@ -294,7 +294,7 @@ SET( zypp_media_HEADERS
media/CredentialFileReader.h
media/CredentialManager.h
media/CurlConfig.h
- media/TransferProgram.h
+ media/TransferSettings.h
)
INSTALL( FILES
diff --git a/zypp/media/MediaAria2c.cc b/zypp/media/MediaAria2c.cc
index 3ae518e..a5de650 100644
--- a/zypp/media/MediaAria2c.cc
+++ b/zypp/media/MediaAria2c.cc
@@ -72,6 +72,225 @@ MediaAria2c::existsAria2cmd()
return ( aria.close() == 0 );
}
+void fillSettingsFromUrl( const Url &url, TransferSettings &s )
+{
+ std::string param(url.getQueryParam("timeout"));
+ if( !param.empty())
+ {
+ long num = str::strtonum<long>(param);
+ if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX)
+ s.setTimeout(num);
+ }
+
+ if ( ! url.getUsername().empty() )
+ {
+ s.setUsername(url.getUsername());
+ if ( url.getPassword().size() )
+ {
+ s.setPassword(url.getPassword());
+ }
+ }
+
+ string proxy = url.getQueryParam( "proxy" );
+
+ if ( ! proxy.empty() )
+ {
+ string proxyport( url.getQueryParam( "proxyport" ) );
+ if ( ! proxyport.empty() ) {
+ proxy += ":" + proxyport;
+ }
+ s.setProxy(proxy);
+ s.setProxyEnabled(true);
+ }
+}
+
+void fillSettingsSystemProxy( const Url&url, TransferSettings &s )
+{
+ ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
+
+ if ( proxy_info.enabled())
+ {
+ s.setProxyEnabled(true);
+ std::list<std::string> nope = proxy_info.noProxy();
+ for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
+ it != proxy_info.noProxyEnd();
+ it++)
+ {
+ std::string host( str::toLower(url.getHost()));
+ std::string temp( str::toLower(*it));
+
+ // no proxy if it points to a suffix
+ // preceeded by a '.', that maches
+ // the trailing portion of the host.
+ if( temp.size() > 1 && temp.at(0) == '.')
+ {
+ if(host.size() > temp.size() &&
+ host.compare(host.size() - temp.size(), temp.size(), temp) == 0)
+ {
+ DBG << "NO_PROXY: '" << *it << "' matches host '"
+ << host << "'" << endl;
+ s.setProxyEnabled(false);
+ break;
+ }
+ }
+ else
+ // no proxy if we have an exact match
+ if( host == temp)
+ {
+ DBG << "NO_PROXY: '" << *it << "' matches host '"
+ << host << "'" << endl;
+ s.setProxyEnabled(false);
+ break;
+ }
+ }
+
+ if ( s.proxyEnabled() )
+ s.setProxy(proxy_info.proxy(url.getScheme()));
+ }
+
+}
+
+/**
+ * comannd line for aria.
+ * The argument list gets passed as reference
+ * and it is filled.
+ */
+void fillAriaCmdLine( const Pathname &ariapath,
+ const TransferSettings &s,
+ const Url &url,
+ const Pathname &destination,
+ ExternalProgram::Arguments &args )
+{
+ args.push_back(ariapath.c_str());
+ args.push_back(str::form("--user-agent=%s", s.userAgentString().c_str()));
+ args.push_back("--summary-interval=1");
+ args.push_back("--follow-metalink=mem");
+ args.push_back("--check-integrity=true");
+
+ // add the anonymous id.
+ for ( TransferSettings::Headers::const_iterator it = s.headersBegin();
+ it != s.headersEnd();
+ ++it )
+ args.push_back(str::form("--header=%s", it->c_str() ));
+
+ args.push_back( str::form("--connect-timeout=%ld", s.timeout()));
+
+ if ( s.username().empty() )
+ {
+ if ( url.getScheme() == "ftp" )
+ {
+ // set anonymous ftp
+ args.push_back(str::form("--ftp-user=%s", "suseuser" ));
+ args.push_back(str::form("--ftp-passwd=%s", VERSION ));
+
+ string id = "yast2";
+ id += VERSION;
+ DBG << "Anonymous FTP identification: '" << id << "'" << endl;
+ }
+ }
+ else
+ {
+ if ( url.getScheme() == "ftp" )
+ args.push_back(str::form("--ftp-user=%s", s.username().c_str() ));
+ else if ( url.getScheme() == "http" ||
+ url.getScheme() == "https" )
+ args.push_back(str::form("--http-user=%s", s.username().c_str() ));
+
+ if ( s.password().size() )
+ {
+ if ( url.getScheme() == "ftp" )
+ args.push_back(str::form("--ftp-passwd=%s", s.password().c_str() ));
+ else if ( url.getScheme() == "http" ||
+ url.getScheme() == "https" )
+ args.push_back(str::form("--http-passwd=%s", s.password().c_str() ));
+ }
+ }
+
+ if ( s.proxyEnabled() )
+ {
+ args.push_back(str::form("--http-proxy=%s", s.proxy().c_str() ));
+ if ( ! s.proxyUsername().empty() )
+ {
+ args.push_back(str::form("--http-proxy-user=%s", s.proxyUsername().c_str() ));
+ if ( ! s.proxyPassword().empty() )
+ args.push_back(str::form("--http-proxy-passwd=%s", s.proxyPassword().c_str() ));
+ }
+ }
+
+ if ( ! destination.empty() )
+ args.push_back(str::form("--dir=%s", destination.c_str()));
+
+ args.push_back(url.asString().c_str());
+}
+
+/**
+ * comannd line for curl.
+ * The argument list gets passed as reference
+ * and it is filled.
+ */
+void fillCurlCmdLine( const Pathname &curlpath,
+ const TransferSettings &s,
+ const Url &url,
+ ExternalProgram::Arguments &args )
+{
+ args.push_back(curlpath.c_str());
+ // only do a head request
+ args.push_back("-I");
+ args.push_back("-A"); args.push_back(s.userAgentString());
+
+ // headers.
+ for ( TransferSettings::Headers::const_iterator it = s.headersBegin();
+ it != s.headersEnd();
+ ++it )
+ {
+ args.push_back("-H");
+ args.push_back(it->c_str());
+ }
+
+ args.push_back("--connect-timeout");
+ args.push_back(str::numstring(s.timeout()));
+
+ if ( s.username().empty() )
+ {
+ if ( url.getScheme() == "ftp" )
+ {
+ string id = "yast2:";
+ id += VERSION;
+ args.push_back("--user");
+ args.push_back(id);
+ DBG << "Anonymous FTP identification: '" << id << "'" << endl;
+ }
+ }
+ else
+ {
+ string userpass = s.username();
+
+ if ( s.password().size() )
+ userpass += (":" + s.password());
+ args.push_back("--user");
+ args.push_back(userpass);
+ }
+
+ if ( s.proxyEnabled() )
+ {
+ args.push_back("--proxy");
+ args.push_back(s.proxy());
+ if ( ! s.proxyUsername().empty() )
+ {
+ string userpass = s.proxyUsername();
+
+ if ( s.proxyPassword().size() )
+ userpass += (":" + s.proxyPassword());
+ args.push_back("--proxy-user");
+ args.push_back(userpass);
+ }
+ }
+
+ args.push_back("--url");
+ args.push_back(url.asString().c_str());
+}
+
+
static const char *const anonymousIdHeader()
{
// we need to add the release and identifier to the
@@ -124,6 +343,7 @@ const char *const MediaAria2c::agentString()
}
+
MediaAria2c::MediaAria2c( const Url & url_r,
const Pathname & attach_point_hint_r )
: MediaHandler( url_r, attach_point_hint_r,
@@ -162,8 +382,6 @@ MediaAria2c::MediaAria2c( const Url & url_r,
void MediaAria2c::attachTo (bool next)
{
// clear last arguments
- _args.clear();
-
if ( next )
ZYPP_THROW(MediaNotSupportedException(_url));
@@ -182,173 +400,25 @@ void MediaAria2c::attachTo (bool next)
disconnectFrom();
- // Build the aria command.
- _args.push_back(_aria2cPath.asString());
- _args.push_back(str::form("--user-agent=%s", agentString()));
- _args.push_back("--summary-interval=1");
- _args.push_back("--follow-metalink=mem");
- _args.push_back( "--check-integrity=true");
-
- // add the anonymous id.
- _args.push_back(str::form("--header=%s", anonymousIdHeader() ));
- _args.push_back(str::form("--header=%s", distributionFlavorHeader() ));
- // TODO add debug option
-
- // Transfer timeout
- {
- _xfer_timeout = TRANSFER_TIMEOUT;
-
- std::string param(_url.getQueryParam("timeout"));
- if( !param.empty())
- {
- long num = str::strtonum<long>( param);
- if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX)
- _xfer_timeout = num;
- }
- }
-
- _args.push_back( str::form("--connect-timeout=%d", CONNECT_TIMEOUT));
-
- // TODO limit redirections
- // TODO Implement certificate validation
+ _settings.setUserAgentString(agentString());
+ _settings.addHeader(anonymousIdHeader());
+ _settings.addHeader(distributionFlavorHeader());
- // FTP defaults to anonymous
+ _settings.setTimeout(TRANSFER_TIMEOUT);
+ _settings.setConnectTimeout(CONNECT_TIMEOUT);
+ // fill some settings from url query parameters
+ fillSettingsFromUrl(_url, _settings);
- if ( _url.getUsername().empty() )
+ // if the proxy was not set by url, then look
+ if ( _settings.proxy().empty() )
{
- if ( _url.getScheme() == "ftp" )
- {
- string id = "yast2@";
- id += VERSION;
- DBG << "Anonymous FTP identification: '" << id << "'" << endl;
- _userpwd = "anonymous:" + id;
- }
+ // at the system proxy settings
+ fillSettingsSystemProxy(_url, _settings);
}
- else
- {
- if ( _url.getScheme() == "ftp" )
- {
- _args.push_back(str::form("--ftp-user=%s", _url.getUsername().c_str() ));
- }
- else if ( _url.getScheme() == "http" ||
- _url.getScheme() == "https" )
- {
- _args.push_back(str::form("--http-user=%s", _url.getUsername().c_str() ));
- }
- if ( _url.getPassword().size() )
- {
- if ( _url.getScheme() == "ftp" )
- {
- _args.push_back(str::form("--ftp-passwd=%s", _url.getPassword().c_str() ));
- }
- else if ( _url.getScheme() == "http" ||
- _url.getScheme() == "https" )
- {
- _args.push_back(str::form("--http-passwd=%s", _url.getPassword().c_str() ));
- }
- }
- }
-
- // note, aria2c does not support setting the auth type with
- // (basic, digest yet)
-
-
- /*---------------------------------------------------------------*
- CURLOPT_PROXY: host[:port]
-
- Url::option(proxy and proxyport)
- If not provided, /etc/sysconfig/proxy is evaluated
- *---------------------------------------------------------------*/
-
- _proxy = _url.getQueryParam( "proxy" );
-
- if ( ! _proxy.empty() )
- {
- string proxyport( _url.getQueryParam( "proxyport" ) );
- if ( ! proxyport.empty() ) {
- _proxy += ":" + proxyport;
- }
- }
- else
- {
-
- ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
-
- if ( proxy_info.enabled())
- {
- bool useproxy = true;
-
- std::list<std::string> nope = proxy_info.noProxy();
- for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
- it != proxy_info.noProxyEnd();
- it++)
- {
- std::string host( str::toLower(_url.getHost()));
- std::string temp( str::toLower(*it));
-
- // no proxy if it points to a suffix
- // preceeded by a '.', that maches
- // the trailing portion of the host.
- if( temp.size() > 1 && temp.at(0) == '.')
- {
- if(host.size() > temp.size() &&
- host.compare(host.size() - temp.size(), temp.size(), temp) == 0)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
- }
- }
- else
- // no proxy if we have an exact match
- if( host == temp)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
- }
- }
-
- if ( useproxy ) {
- _proxy = proxy_info.proxy(_url.getScheme());
- }
- }
- }
-
- DBG << "Proxy: " << (_proxy.empty() ? "-none-" : _proxy) << endl;
-
- if ( ! _proxy.empty() )
- {
- _args.push_back(str::form("--http-proxy=%s", _proxy.c_str() ));
-
- /*---------------------------------------------------------------*
- CURLOPT_PROXYUSERPWD: [user name]:[password]
+ DBG << "Proxy: " << (_settings.proxy().empty() ? "-none-" : _settings.proxy()) << endl;
- Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
- If not provided, $HOME/.curlrc is evaluated
- *---------------------------------------------------------------*/
-
- _proxyuserpwd = _url.getQueryParam( "proxyuser" );
-
- if ( ! _proxyuserpwd.empty() ) {
- _args.push_back(str::form("--http-proxy-user=%s", _proxyuserpwd.c_str() ));
-
- string proxypassword( _url.getQueryParam( "proxypassword" ) );
- if ( ! proxypassword.empty() ) {
- _args.push_back(str::form("--http-proxy-passwd=%s", proxypassword.c_str() ));
- }
- }
- }
-
- //_currentCookieFile = _cookieFile.asString();
- //_args.push_back(str::form("--load-cookies=%s", _currentCookieFile.c_str()));
- //NOTE cookie jar?
-
- // FIXME: need a derived class to propelly compare url's
MediaSourceRef media( new MediaSource(_url.getScheme(), _url.asString()));
setMediaSource(media);
@@ -412,11 +482,10 @@ void MediaAria2c::getFileCopy( const Pathname & filename , const Pathname & targ
bool retry = false;
- ExternalProgram::Arguments args = _args;
- args.push_back(str::form("--dir=%s", target.dirname().c_str()));
-
- args.push_back(fileurl.asString());
+ ExternalProgram::Arguments args;
+ fillAriaCmdLine(_aria2cPath, _settings, fileurl, target.dirname(), args);
+
do
{
try
@@ -525,8 +594,71 @@ bool MediaAria2c::getDoesFileExist( const Pathname & filename ) const
bool MediaAria2c::doGetDoesFileExist( const Pathname & filename ) const
{
-
DBG << filename.asString() << endl;
+ callback::SendReport<DownloadProgressReport> report;
+
+ Url fileurl(getFileUrl(_url, filename));
+ bool retry = false;
+
+ ExternalProgram::Arguments args;
+
+ fillCurlCmdLine("/usr/bin/curl", _settings, fileurl, args);
+
+ do
+ {
+ try
+ {
+ report->start(_url, fileurl.asString() );
+
+ ExternalProgram curl(args, ExternalProgram::Stderr_To_Stdout);
+ //Process response
+ for(std::string curlResponse( curl.receiveLine());
+ curlResponse.length();
+ curlResponse = curl.receiveLine())
+ {
+
+ if ( str::contains(curlResponse, "401 Authorization Required") )
+ {
+ ZYPP_THROW(MediaUnauthorizedException(
+ _url, "Login failed.", "Login failed", "auth hint"
+ ));
+ }
+
+ if ( str::contains(curlResponse, "404 Not Found") )
+ return false;
+
+ if ( str::contains(curlResponse, "200 OK") )
+ return false;
+ }
+
+ int code = curl.close();
+
+ report->finish( _url , zypp::media::DownloadProgressReport::NO_ERROR, "");
+ retry = false;
+ }
+ // retry with proper authentication data
+ catch (MediaUnauthorizedException & ex_r)
+ {
+ if(authenticate(ex_r.hint(), !retry))
+ retry = true;
+ else
+ {
+ report->finish(fileurl, zypp::media::DownloadProgressReport::ACCESS_DENIED, ex_r.asUserHistory());
+ ZYPP_RETHROW(ex_r);
+ }
+
+ }
+ // unexpected exception
+ catch (MediaException & excpt_r)
+ {
+ // FIXME: error number fix
+ report->finish(fileurl, zypp::media::DownloadProgressReport::ERROR, excpt_r.asUserHistory());
+ ZYPP_RETHROW(excpt_r);
+ }
+ }
+ while (retry);
+
+ report->finish(fileurl, zypp::media::DownloadProgressReport::NO_ERROR, "");
return true;
}
diff --git a/zypp/media/MediaAria2c.h b/zypp/media/MediaAria2c.h
index 4b83552..1020ea5 100644
--- a/zypp/media/MediaAria2c.h
+++ b/zypp/media/MediaAria2c.h
@@ -13,6 +13,7 @@
#define ZYPP_MEDIA_MEDIAARIA2C_H
#include "zypp/media/MediaHandler.h"
+#include "zypp/media/TransferSettings.h"
#include "zypp/ZYppCallbacks.h"
namespace zypp {
@@ -111,7 +112,7 @@ class MediaAria2c : public MediaHandler {
std::string getAria2cVersion();
static std::string _aria2cVersion;
- ExternalProgram::Arguments _args;
+ TransferSettings _settings;
};
///////////////////////////////////////////////////////////////////
diff --git a/zypp/media/TransferProgram.cc b/zypp/media/TransferProgram.cc
deleted file mode 100644
index 2542fed..0000000
--- a/zypp/media/TransferProgram.cc
+++ /dev/null
@@ -1,206 +0,0 @@
-#include <iostream>
-#include <vector>
-#include <sstream>
-
-#include "zypp/base/String.h"
-#include "zypp/base/Logger.h"
-#include "zypp/base/WatchFile.h"
-#include "zypp/base/ReferenceCounted.h"
-#include "zypp/base/NonCopyable.h"
-#include "zypp/ExternalProgram.h"
-#include "zypp/media/TransferProgram.h"
-
-using namespace std;
-
-#define ARIA2C_BINARY "/usr/bin/aria2c"
-#define CURL_BINARY "/usr/bin/curl"
-
-namespace zypp
-{
-namespace media
-{
-
-class TransferProgram::Impl
-{
-public:
- Impl()
- : _useproxy(false)
- , _timeout(0)
- {}
-
- virtual ~Impl()
- {}
-
- virtual void execute()
- {
- ERR << "not implemented." << endl;
- ZYPP_THROW(Exception("not implemented"));
- }
-
- /** Offer default Impl. */
- static shared_ptr<Impl> nullimpl()
- {
- static shared_ptr<Impl> _nullimpl( new Impl );
- return _nullimpl;
- }
-
-private:
- friend Impl * rwcowClone<Impl>( const Impl * rhs );
- /** clone for RWCOW_pointer */
- Impl * clone() const
- { return new Impl( *this ); }
-
-public:
- vector<string> _headers;
- string _useragent;
- string _username;
- string _password;
- bool _useproxy;
- string _proxy_username;
- string _proxy_password;
- int _timeout;
- Url _url;
-
- TransferProgram::OutputLines _output;
- ErrorFlags _errorFlags;
- int _exitCode;
-};
-
-class Aria2cProgram : public TransferProgram::Impl
-{
-public:
- virtual void execute()
- {
- ExternalProgram::Arguments args;
-
- args.push_back(ARIA2C_BINARY);
- args.push_back(str::form("--user-agent=%s", _useragent.c_str()));
- args.push_back("--summary-interval=1");
- args.push_back("--follow-metalink=mem");
- args.push_back("--check-integrity=true");
-
- // add the anonymous id.
- for ( vector<string>::const_iterator it = _headers.begin();
- it != _headers.end();
- ++it )
- args.push_back(str::form("--header=%s", it->c_str() ));
-
- args.push_back( str::form("--connect-timeout=%d", _timeout));
-
- ExternalProgram prog(args,ExternalProgram::Discard_Stderr, false, -1, true);
- string line;
- int count;
- for(line = prog.receiveLine(), count=0;
- !line.empty();
- line = prog.receiveLine(), count++ )
- {
- // save the line
- _output.push_back(line);
-
- // trim trailing NL.
- if ( line.empty() )
- continue;
- // make sure no \n is at the end
- line = str::rtrim(line);
-
- // process lines
- }
- _exitCode = prog.close();
-
- // clear previous argument
- args.clear();
- }
-};
-
-class CurlProgram : public TransferProgram::Impl
-{
-public:
- virtual void execute()
- {
- }
-};
-
-
-TransferProgram::TransferProgram()
- : _impl()
-{
-
-}
-
-TransferProgram::OutputLines::const_iterator TransferProgram::outputLinesBegin() const
-{
- return _impl->_output.begin();
-}
-
-TransferProgram::OutputLines::const_iterator TransferProgram::outputLinesEnd() const
-{
- return _impl->_output.end();
-}
-
-string TransferProgram::output() const
-{
- stringstream str;
- OutputLines::const_iterator it;
- for ( it = outputLinesBegin();
- it != outputLinesEnd();
- ++it )
- {
- str << *it;
- }
- return str.str();
-}
-
-void TransferProgram::execute()
-{
- _impl->execute();
-}
-
-void TransferProgram::addHeader( const std::string &header )
-{
- _impl->_headers.push_back(header);
-}
-
-void TransferProgram::setUserAgentString( const std::string &agent )
-{
- _impl->_useragent = agent;
-}
-
-void TransferProgram::setUsername( const std::string &username )
-{
- _impl->_username = username;
-}
-
-void TransferProgram::setPassword( const std::string &password )
-{
- _impl->_password = password;
-}
-
-void TransferProgram::setProxyEnabled( bool enabled )
-{
- _impl->_useproxy = enabled;
-}
-
-void TransferProgram::setProxyUsername( const std::string &proxyuser )
-{
- _impl->_proxy_username = proxyuser;
-}
-
-void TransferProgram::setProxyPassword( const std::string &proxypass )
-{
- _impl->_proxy_password = proxypass;
-}
-
-void TransferProgram::setTimeout( int t )
-{
- _impl->_timeout = t;
-}
-
-void TransferProgram::setUrl( const zypp::Url &url)
-{
- _impl->_url = url;
-}
-
-
-} // ns media
-} // ns zypp
-
diff --git a/zypp/media/TransferProgram.h b/zypp/media/TransferProgram.h
deleted file mode 100644
index 4441c62..0000000
--- a/zypp/media/TransferProgram.h
+++ /dev/null
@@ -1,135 +0,0 @@
-
-#ifndef TRANSFER_PROGRAM_H_
-#define TRANSFER_PROGRAM_H_
-
-#include <functional>
-#include <list>
-#include <string>
-#include <vector>
-#include "zypp/base/Flags.h"
-#include "zypp/base/PtrTypes.h"
-#include "zypp/Pathname.h"
-#include "zypp/Url.h"
-
-namespace zypp
-{
-namespace media
-{
-
-/**
- * Easy access to the transfer command line program
- *
- */
-class TransferProgram
-{
-public:
-
- typedef std::vector<std::string> OutputLines;
-
- /**
- * After calling the program, one or more error flags can
- * be set according to the result.
- */
- enum ErrorFlag
- {
- /** Operation ended successfully */
- NO_ERROR = 0x0,
- };
- ZYPP_DECLARE_FLAGS(ErrorFlags,ErrorFlag);
-
- /**
- * Constructs a gpg cmd line access.
- * \p home is the home directory where keyrings are created.
- *
- * Gpg has one pubkeyring and one secret keyring in its home.
- *
- */
- TransferProgram();
-
- /**
- * Executes command with a given argument
- */
- void execute();
-
- /**
- * Contains the error flags from the last command execution
- */
- ErrorFlags errorFlags() const;
-
- /**
- * contains the last command execution exit code
- */
- int exitCode() const;
-
- /**
- * begin iterator over output lines available after
- * execute
- */
- OutputLines::const_iterator outputLinesBegin() const;
-
- /**
- * end iterator over output lines available after
- * execute
- */
- OutputLines::const_iterator outputLinesEnd() const;
-
- /**
- * returns the full output for convenience
- */
- std::string output() const;
-
- /**
- * add a header, on the form "Foo: Bar"
- */
- void addHeader( const std::string &header );
-
- /**
- * sets the user agent ie: "Mozilla v3"
- */
- void setUserAgentString( const std::string &agent );
-
- /**
- * sets the auth username
- */
- void setUsername( const std::string &username );
-
- /**
- * sets the auth password
- */
- void setPassword( const std::string &password );
-
- /**
- * whether the proxy is used or not
- */
- void setProxyEnabled( bool enabled );
-
- /**
- * sets the proxy user
- */
- void setProxyUsername( const std::string &proxyuser );
-
- /**
- * sets the proxy password
- */
- void setProxyPassword( const std::string &proxypass );
-
- /**
- * set the connection timeout
- */
- void setTimeout( int t );
-
- /**
- * set url to download
- */
- void setUrl( const zypp::Url &url);
-
- class Impl;
-protected:
- RWCOW_pointer<Impl> _impl;
-};
-ZYPP_DECLARE_OPERATORS_FOR_FLAGS(TransferProgram::ErrorFlags);
-
-} // ns media
-} // ns zypp
-
-#endif
diff --git a/zypp/media/TransferSettings.cc b/zypp/media/TransferSettings.cc
new file mode 100644
index 0000000..e50a3a5
--- /dev/null
+++ b/zypp/media/TransferSettings.cc
@@ -0,0 +1,176 @@
+#include <iostream>
+#include <vector>
+#include <sstream>
+
+#include "zypp/base/String.h"
+#include "zypp/base/Logger.h"
+#include "zypp/base/WatchFile.h"
+#include "zypp/base/ReferenceCounted.h"
+#include "zypp/base/NonCopyable.h"
+#include "zypp/ExternalProgram.h"
+#include "zypp/media/TransferSettings.h"
+
+using namespace std;
+
+#define ARIA2C_BINARY "/usr/bin/aria2c"
+#define CURL_BINARY "/usr/bin/curl"
+
+namespace zypp
+{
+namespace media
+{
+
+class TransferSettings::Impl
+{
+public:
+ Impl()
+ : _useproxy(false)
+ , _timeout(0)
+ , _connect_timeout(0)
+ {}
+
+ virtual ~Impl()
+ {}
+
+ /** Offer default Impl. */
+ static shared_ptr<Impl> nullimpl()
+ {
+ static shared_ptr<Impl> _nullimpl( new Impl );
+ return _nullimpl;
+ }
+
+private:
+ friend Impl * rwcowClone<Impl>( const Impl * rhs );
+ /** clone for RWCOW_pointer */
+ Impl * clone() const
+ { return new Impl( *this ); }
+
+public:
+ vector<string> _headers;
+ string _useragent;
+ string _username;
+ string _password;
+ bool _useproxy;
+ string _proxy;
+ string _proxy_username;
+ string _proxy_password;
+ long _timeout;
+ long _connect_timeout;
+ Url _url;
+ Pathname _targetdir;
+};
+
+TransferSettings::TransferSettings()
+ : _impl(new TransferSettings::Impl())
+{
+
+}
+
+void TransferSettings::addHeader( const std::string &header )
+{
+ _impl->_headers.push_back(header);
+}
+
+TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
+{
+ return _impl->_headers.begin();
+}
+
+TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
+{
+ return _impl->_headers.end();
+}
+
+void TransferSettings::setUserAgentString( const std::string &agent )
+{
+ _impl->_useragent = agent;
+}
+
+std::string TransferSettings::userAgentString() const
+{
+ return _impl->_useragent;
+}
+
+void TransferSettings::setUsername( const std::string &username )
+{
+ _impl->_username = username;
+}
+
+std::string TransferSettings::username() const
+{
+ return _impl->_username;
+}
+
+void TransferSettings::setPassword( const std::string &password )
+{
+ _impl->_password = password;
+}
+
+std::string TransferSettings::password() const
+{
+ return _impl->_password;
+}
+
+void TransferSettings::setProxyEnabled( bool enabled )
+{
+ _impl->_useproxy = enabled;
+}
+
+bool TransferSettings::proxyEnabled() const
+{
+ return _impl->_useproxy;
+}
+
+void TransferSettings::setProxy( const std::string &proxy )
+{
+ _impl->_proxy = proxy;
+}
+
+std::string TransferSettings::proxy() const
+{
+ return _impl->_proxy;
+}
+
+void TransferSettings::setProxyUsername( const std::string &proxyuser )
+{
+ _impl->_proxy_username = proxyuser;
+}
+
+std::string TransferSettings::proxyUsername() const
+{
+ return _impl->_proxy_username;
+}
+
+void TransferSettings::setProxyPassword( const std::string &proxypass )
+{
+ _impl->_proxy_password = proxypass;
+}
+
+std::string TransferSettings::proxyPassword() const
+{
+ return _impl->_proxy_password;
+}
+
+void TransferSettings::setTimeout( long t )
+{
+ _impl->_timeout = t;
+}
+
+long TransferSettings::timeout() const
+{
+ return _impl->_timeout;
+}
+
+void TransferSettings::setConnectTimeout( long t )
+{
+ _impl->_connect_timeout = t;
+}
+
+long TransferSettings::connectTimeout() const
+{
+ return _impl->_connect_timeout;
+}
+
+} // ns media
+} // ns zypp
+
diff --git a/zypp/media/TransferSettings.h b/zypp/media/TransferSettings.h
new file mode 100644
index 0000000..3a513f0
--- /dev/null
+++ b/zypp/media/TransferSettings.h
@@ -0,0 +1,151 @@
+
+#ifndef TRANSFER_PROGRAM_H_
+#define TRANSFER_PROGRAM_H_
+
+#include <string>
+#include <vector>
+#include "zypp/base/Flags.h"
+#include "zypp/base/PtrTypes.h"
+#include "zypp/Pathname.h"
+#include "zypp/Url.h"
+
+namespace zypp
+{
+namespace media
+{
+
+/**
+ * Easy access to the transfer command line program no matter
+ * which one it is
+ *
+ */
+class TransferSettings
+{
+public:
+ /**
+ * Constructs a transfer program cmd line access.
+ */
+ TransferSettings();
+
+ /**
+ * Constructs the settings from a url object where.
+ * authentication/proxy information can be extracted
+ * from the url
+ */
+ TransferSettings( const zypp::Url &url );
+
+ typedef std::vector<std::string> Headers;
+ /**
+ * add a header, on the form "Foo: Bar"
+ */
+ void addHeader( const std::string &header );
+
+ /**
+ * begin iterators to additional headers
+ */
+ Headers::const_iterator headersBegin() const;
+
+ /**
+ * end iterators to additional headers
+ */
+ Headers::const_iterator headersEnd() const;
+
+ /**
+ * sets the user agent ie: "Mozilla v3"
+ */
+ void setUserAgentString( const std::string &agent );
+
+ /**
+ * user agent string
+ */
+ std::string userAgentString() const;
+
+ /**
+ * sets the auth username
+ */
+ void setUsername( const std::string &username );
+
+ /**
+ * auth username
+ */
+ std::string username() const;
+
+ /**
+ * sets the auth password
+ */
+ void setPassword( const std::string &password );
+
+ /**
+ * auth password
+ */
+ std::string password() const;
+
+ /**
+ * whether the proxy is used or not
+ */
+ void setProxyEnabled( bool enabled );
+
+ /**
+ * proxy is enabled
+ */
+ bool proxyEnabled() const;
+
+ /**
+ * proxy to use if it is enabled
+ */
+ void setProxy( const std::string &proxyhost );
+
+ /**
+ * proxy host
+ */
+ std::string proxy() const;
+
+ /**
+ * sets the proxy user
+ */
+ void setProxyUsername( const std::string &proxyuser );
+
+ /**
+ * proxy auth username
+ */
+ std::string proxyUsername() const;
+
+ /**
+ * sets the proxy password
+ */
+ void setProxyPassword( const std::string &proxypass );
+
+ /**
+ * proxy auth password
+ */
+ std::string proxyPassword() const;
+
+ /**
+ * set the connect timeout
+ */
+ void setConnectTimeout( long t );
+
+ /**
+ * connection timeout
+ */
+ long connectTimeout() const;
+
+ /**
+ * set the transfer timeout
+ */
+ void setTimeout( long t );
+
+ /**
+ * transfer timeout
+ */
+ long timeout() const;
+
+protected:
+ class Impl;
+ RWCOW_pointer<Impl> _impl;
+};
+
+} // ns media
+} // ns zypp
+
+#endif
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0