return result;
}
-#define WEBRICK 1
+#define WEBRICK 0
class WebServer::Impl
{
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[] =
{
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;
}
return _port;
}
-
+
virtual string log() const
{
return _log;
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;
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;
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:
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")
/*
*
*/
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);
*/
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")));
*/
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")));
*/
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);
*/
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);
*/
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);
*/
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"));
*/
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();
}
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));
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;
}