14#include <zypp-curl/parser/ZsyncParser>
15#include <zypp-core/fs/PathInfo.h>
19#if ENABLE_ZCHUNK_COMPRESSION
26 : SimpleState( parent )
28 , _oldRequest( oldReq )
30 MIL <<
"About to enter PrepareMultiState for URL: " << parent.
_spec.
url() << std::endl;
35 auto &sm = stateMachine();
36 const auto &spec = sm._spec;
37 const auto &url = spec.url();
38 const auto &targetPath = spec.targetPath();
39#if ENABLE_ZCHUNK_COMPRESSION
40 _haveZckData = (isZchunkFile( spec.deltaFile() ) && spec.headerSize() > 0);
41 MIL <<
" Upgrading request for URL: "<< url <<
" to multipart download , which zckunk=" << _haveZckData << std::endl;
43 MIL <<
" Upgrading request for URL: "<< url <<
" to multipart download , which zckunk=false" << std::endl;
50 std::vector<zypp::media::MetalinkMirror> mirrs;
54 const auto &parseMetadata = [&](
auto &&parser ) {
55 using T = std::decay_t<
decltype (parser)>;
56 constexpr auto metalinkMode = std::is_same< T, zypp::media::MetaLinkParser>();
58 parser.parse( targetPath );
61 #if ENABLE_ZCHUNK_COMPRESSION
62 if ( !_haveZckData ) {
66 auto bl = parser.getBlockList();
67 if ( !bl.haveBlocks() )
68 MIL <<
"Got no blocks for URL " << spec.url() <<
" but got filesize? " << bl.getFilesize() << std::endl;
69 if ( bl.haveBlocks() || bl.haveFilesize() )
74 if constexpr ( !metalinkMode ) {
75 const auto &urlList = parser.getUrls();
76 std::for_each( urlList.begin(), urlList.end(), [&](
const auto &url ) {
77 mirrs.push_back( { 0, -1, url } );
80 mirrs = parser.getMirrors();
83 for (
auto urliter = mirrs.begin(); urliter != mirrs.end(); ++urliter ) {
85 const std::string scheme = urliter->url.getScheme();
86 if (scheme ==
"http" || scheme ==
"https" || scheme ==
"ftp" || scheme ==
"tftp") {
87 if ( !sm._requestDispatcher->supportsProtocol( urliter->url )) {
88 urliter = mirrs.erase( urliter );
98 if ( mirrs.empty() ) {
99 mirrs.push_back( { 0, -1, url } );
116 WAR << err << std::endl;
122 if ( mirrs.size() == 0 ) {
123 std::string err =
zypp::str::Format(
"Invalid metalink information.( No mirrors in metalink file)" );
124 WAR << err << std::endl;
135 sm._mirrorControl->registerMirrors( mirrs );
147 auto &sm = stateMachine();
148 const auto &spec = sm._spec;
149 const auto &url = spec.url();
152#if ENABLE_ZCHUNK_COMPRESSION
153 if ( _haveZckData ) {
171 MIL <<
"Generate blocklist, since there was none in the metalink file." << url << std::endl;
177 while ( currOff < filesize ) {
179 auto blksize = filesize - currOff ;
180 if ( blksize > prefSize )
187 MIL_MEDIA <<
"Generated blocklist: " << std::endl <<
_blockList << std::endl <<
" End blocklist " << std::endl;
196 MIL <<
"No blocklist and no filesize, falling back to normal download for URL " << stateMachine()._spec.url() << std::endl;
197 std::shared_ptr<DlNormalFileState> ptr;
199 ptr = std::make_shared<DlNormalFileState>( std::move(
_oldRequest), stateMachine() );
201 ptr = std::make_shared<DlNormalFileState>( stateMachine() );
204 ptr->_fileMirrors = std::move(
_mirrors);
215 return std::make_shared<DlMetalinkState>( std::move(
_blockList), std::move(
_mirrors), stateMachine() );
220 return std::make_shared<FinishedState>( std::move(
_error), stateMachine() );
223#if ENABLE_ZCHUNK_COMPRESSION
224 std::shared_ptr<DLZckHeadState> PrepareMultiState::transitionToZckHeadDl()
227 return std::make_shared<DLZckHeadState>( std::move(
_mirrors), std::move(
_oldRequest), stateMachine() );
228 return std::make_shared<DLZckHeadState>( std::move(
_mirrors), stateMachine() );
231 bool PrepareMultiState::toZckHeadDownloadGuard()
const
233 return ( stateMachine().hasZckInfo() );
239#if ENABLE_ZCHUNK_COMPRESSION
240 return (!toZckHeadDownloadGuard());
Store and operate with byte count.
static const Unit K
1024 Byte
Base class for Exception.
std::string asUserString() const
Translated error message as string suitable for the user.
SignalProxy< void()> sigNewMirrorsReady()
static zyppng::NetworkRequestError customError(NetworkRequestError::Type t, std::string &&errorMsg="", std::map< std::string, boost::any > &&extraInfo={})
zypp::Url propagateQueryParams(zypp::Url url_r, const zypp::Url &template_r)
int unlink(const Pathname &path)
Like 'unlink'.
PrepareMultiState(std::shared_ptr< Request > oldReq, Mode m, DownloadPrivate &parent)
NetworkRequestError _error
Signal< void() > _sigFailed
std::vector< Url > _mirrors
std::shared_ptr< DlNormalFileState > fallbackToNormalTransition()
std::shared_ptr< FinishedState > transitionToFinished()
sigc::connection _mirrorControlReadyConn
std::shared_ptr< DlMetalinkState > transitionToMetalinkDl()
Signal< void() > _sigFinished
bool toMetalinkDownloadGuard() const
zypp::media::MediaBlockList _blockList
Signal< void() > _sigFallback
std::shared_ptr< Request > _oldRequest