15 #include <zypp-curl/parser/ZsyncParser> 20 #if ENABLE_ZCHUNK_COMPRESSION 27 : SimpleState( parent )
29 , _oldRequest(
std::move( oldReq ))
31 MIL <<
"About to enter PrepareMultiState for URL: " << parent.
_spec.
url() << std::endl;
36 auto &sm = stateMachine();
37 const auto &spec = sm._spec;
38 const auto &url = spec.url();
39 const auto &targetPath = spec.targetPath();
40 #if ENABLE_ZCHUNK_COMPRESSION 41 _haveZckData = (isZchunkFile( spec.deltaFile() ) && spec.headerSize() > 0);
42 MIL <<
" Upgrading request for URL: "<< url <<
" to multipart download , which zckunk=" << _haveZckData << std::endl;
44 MIL <<
" Upgrading request for URL: "<< url <<
" to multipart download , which zckunk=false" << std::endl;
51 std::vector<zypp::media::MetalinkMirror> mirrs;
55 const auto &parseMetadata = [&](
auto &&parser ) {
56 using T = std::decay_t<decltype (parser)>;
57 constexpr
auto metalinkMode = std::is_same< T, zypp::media::MetaLinkParser>();
59 parser.parse( targetPath );
62 #if ENABLE_ZCHUNK_COMPRESSION 63 if ( !_haveZckData ) {
67 auto bl = parser.getBlockList();
68 if ( !bl.haveBlocks() )
69 MIL <<
"Got no blocks for URL " << spec.url() <<
" but got filesize? " << bl.getFilesize() << std::endl;
70 if ( bl.haveBlocks() || bl.haveFilesize() )
75 if constexpr ( !metalinkMode ) {
76 const auto &urlList = parser.getUrls();
77 std::for_each( urlList.begin(), urlList.end(), [&](
const auto &url ) {
78 mirrs.push_back( { 0, -1, url } );
81 mirrs = parser.getMirrors();
84 for (
auto urliter = mirrs.begin(); urliter != mirrs.end(); ++urliter ) {
86 const std::string scheme = urliter->url.getScheme();
87 if (scheme ==
"http" || scheme ==
"https" || scheme ==
"ftp" || scheme ==
"tftp") {
88 if ( !sm._requestDispatcher->supportsProtocol( urliter->url )) {
89 urliter = mirrs.erase( urliter );
99 if ( mirrs.empty() ) {
100 mirrs.push_back( { 0, -1, url } );
117 WAR << err << std::endl;
123 if ( mirrs.size() == 0 ) {
124 std::string err =
zypp::str::Format(
"Invalid metalink information.( No mirrors in metalink file)" );
125 WAR << err << std::endl;
136 sm._mirrorControl->registerMirrors( mirrs );
148 auto &sm = stateMachine();
149 const auto &spec = sm._spec;
150 const auto &url = spec.url();
153 #if ENABLE_ZCHUNK_COMPRESSION 154 if ( _haveZckData ) {
172 MIL <<
"Generate blocklist, since there was none in the metalink file." << url << std::endl;
178 while ( currOff < filesize ) {
180 auto blksize = filesize - currOff ;
181 if ( blksize > prefSize )
188 MIL_MEDIA <<
"Generated blocklist: " << std::endl <<
_blockList << std::endl <<
" End blocklist " << std::endl;
197 MIL <<
"No blocklist and no filesize, falling back to normal download for URL " << stateMachine()._spec.url() << std::endl;
198 std::shared_ptr<DlNormalFileState> ptr;
200 ptr = std::make_shared<DlNormalFileState>( std::move(
_oldRequest), stateMachine() );
202 ptr = std::make_shared<DlNormalFileState>( stateMachine() );
205 ptr->_fileMirrors = std::move(
_mirrors);
216 return std::make_shared<DlMetalinkState>( std::move(
_blockList), std::move(
_mirrors), stateMachine() );
221 return std::make_shared<FinishedState>( std::move(
_error), stateMachine() );
224 #if ENABLE_ZCHUNK_COMPRESSION 225 std::shared_ptr<DLZckHeadState> PrepareMultiState::transitionToZckHeadDl()
228 return std::make_shared<DLZckHeadState>( std::move(
_mirrors), std::move(
_oldRequest), stateMachine() );
229 return std::make_shared<DLZckHeadState>( std::move(
_mirrors), stateMachine() );
232 bool PrepareMultiState::toZckHeadDownloadGuard()
const 234 return ( stateMachine().hasZckInfo() );
240 #if ENABLE_ZCHUNK_COMPRESSION 241 return (!toZckHeadDownloadGuard());
SignalProxy< void()> sigNewMirrorsReady()
std::shared_ptr< DlMetalinkState > transitionToMetalinkDl()
Signal< void() > _sigFailed
zypp::Url propagateQueryParams(zypp::Url url_r, const zypp::Url &template_r)
Store and operate with byte count.
sigc::connection _mirrorControlReadyConn
zypp::media::MediaBlockList _blockList
NetworkRequestError _error
std::shared_ptr< Request > _oldRequest
int unlink(const Pathname &path)
Like 'unlink'.
std::string asUserString() const
Translated error message as string suitable for the user.
PrepareMultiState(std::shared_ptr< Request > oldReq, Mode m, DownloadPrivate &parent)
Signal< void() > _sigFallback
std::vector< Url > _mirrors
Signal< void() > _sigFinished
Base class for Exception.
static const Unit K
1024 Byte
std::shared_ptr< DlNormalFileState > fallbackToNormalTransition()
static zyppng::NetworkRequestError customError(NetworkRequestError::Type t, std::string &&errorMsg="", std::map< std::string, boost::any > &&extraInfo={})
bool toMetalinkDownloadGuard() const
std::shared_ptr< FinishedState > transitionToFinished()