3 #include "zypp/base/String.h"
4 #include "zypp/OnMediaLocation.h"
5 #include "zypp/MediaSetAccess.h"
6 #include "zypp/Fetcher.h"
7 #include "zypp/repo/MediaInfoDownloader.h"
9 #include "zypp/repo/susetags/Downloader.h"
10 #include "zypp/base/UserRequestException.h"
21 Downloader::Downloader( const Url &url, const Pathname &path )
22 : _url(url), _path(path)
27 RepoStatus Downloader::status()
29 MediaSetAccess media(_url, _path);
30 Pathname content = media.provideFile("/content");
31 return RepoStatus(content);
34 void Downloader::download( const Pathname &dest_dir,
35 const ProgressData::ReceiverFnc & progress )
37 MediaSetAccess media(_url);
39 downloadMediaInfo( dest_dir, media );
41 SignatureFileChecker sigchecker;
43 Pathname sig = _path + "/content.asc";
44 if ( media.doesFileExist(sig) )
46 fetcher.enqueue( OnMediaLocation( sig, 1 ) );
47 fetcher.start( dest_dir, media );
50 sigchecker = SignatureFileChecker( dest_dir + sig );
53 Pathname key = _path + "/content.key";
54 if ( media.doesFileExist(key) )
56 fetcher.enqueue( OnMediaLocation( key, 1 ) );
57 fetcher.start( dest_dir, media );
59 sigchecker.addPublicKey(dest_dir + key);
63 fetcher.enqueue( OnMediaLocation( _path + "/content", 1 ), sigchecker );
64 fetcher.start( dest_dir, media );
67 std::ifstream file((dest_dir + _path + "/content").asString().c_str());
71 // FIXME Note this code assumes DESCR comes before as META
73 while (file && !file.eof())
75 getline(file, buffer);
76 if ( buffer.substr( 0, 5 ) == "DESCR" )
78 std::vector<std::string> words;
79 if ( str::split( buffer, std::back_inserter(words) ) != 2 )
82 ZYPP_THROW(Exception("bad DESCR line"));
86 else if ( buffer.substr( 0, 4 ) == "META" )
88 std::vector<std::string> words;
89 if ( str::split( buffer, std::back_inserter(words) ) != 4 )
92 ZYPP_THROW(Exception("bad META line"));
94 OnMediaLocation location( _path + descr_dir + words[3], 1 );
95 location.setChecksum( CheckSum( words[1], words[2] ) );
96 fetcher.enqueueDigested(location);
98 else if (buffer.substr( 0, 3 ) == "KEY")
100 std::vector<std::string> words;
101 if ( str::split( buffer, std::back_inserter(words) ) != 4 )
104 ZYPP_THROW(Exception("bad KEY line"));
106 OnMediaLocation location( _path + words[3], 1 );
107 location.setChecksum( CheckSum( words[1], words[2] ) );
108 fetcher.enqueueDigested(location);
112 fetcher.start( dest_dir, media );