16 #include <zypp-core/base/UserRequestException> 17 #include <zypp-media/MediaException> 24 #undef ZYPP_BASE_LOGGER_LOGGROUP 25 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::fetcher" 38 Impl( std::vector<media::MediaUrl> &&urls,
Pathname &&prefered_attach_point )
43 Impl( std::string &&label_r, std::vector<media::MediaUrl> &&urls,
Pathname &&prefered_attach_point)
50 std::vector<media::MediaUrl>
_urls;
62 using MediaMap = std::map<media::MediaNr, media::MediaAccessId>;
63 using VerifierMap = std::map<media::MediaNr, media::MediaVerifierRef>;
74 :
MediaSetAccess( { media::MediaUrl( std::move(url)) }, std::move(prefered_attach_point) )
78 :
MediaSetAccess(
std::move(label_r), { media::MediaUrl( std::move(url)) }, std::move(prefered_attach_point) )
82 : _pimpl(
std::make_unique<
Impl>(
std::move(urls),
std::move(prefered_attach_point) ) )
86 : _pimpl(
std::make_unique<
Impl>(
std::move(label_r),
std::move(urls),
std::move(prefered_attach_point) ) )
94 for (
const auto & mm :
_pimpl->_medias )
95 manager.
close( mm.second );
103 if (
_pimpl->_medias.find(media_nr) !=
_pimpl->_medias.end())
110 _pimpl->_verifiers.erase(media_nr);
121 {
return _pimpl->_label; }
124 {
_pimpl->_label = label_r; }
135 DBG <<
"Going to release file " << file
136 <<
" from media number " << media_nr << endl;
145 bool dots,
unsigned media_nr )
154 media_mgr.
dirInfo(media, retlist, dirname, dots);
173 const auto &fName = file.
filename();
185 const auto &fName = file.
filename();
201 const auto &fName = file.
filename();
210 provide( std::ref(op), resource, options );
284 for (
const auto &resource : files ) {
285 unsigned media_nr(resource.medianr());
288 if ( !media_mgr.
isOpen( media ) ) {
289 MIL <<
"Skipping precache of file " << resource.filename() <<
" media is not open";
302 ProvideFileOptions options )
304 const auto &file(resource.
filename());
305 unsigned media_nr(resource.
medianr());
319 DBG <<
"Going to try to provide " << (resource.
optional() ?
"optional" :
"") <<
" file " << file
320 <<
" from media number " << media_nr << endl;
331 unsigned int devindex = 0;
332 std::vector<std::string> devices;
361 MIL <<
"Can't provide file. Non-Interactive mode." << endl;
370 user = report->requestMedia (
382 if ( u !=
_pimpl->_urls.at(0).url() ) {
383 MIL <<
"User changed the URL, dropping all mirrors" << std::endl;
385 _pimpl->_urls.push_back( u );
389 MIL <<
"ProvideFile exception caught, callback answer: " << user << endl;
393 DBG <<
"Aborting" << endl;
394 AbortRequestException aexcp(
"Aborting requested by user");
395 aexcp.remember(excp);
400 DBG <<
"Skipping" << endl;
401 SkipRequestException nexcp(
"User-requested skipping of a file");
402 nexcp.remember(excp);
407 DBG <<
"Eject: try to release" << endl;
411 media_mgr.
release (media, devindex < devices.size() ? devices[devindex] :
"");
422 DBG <<
"Going to try again" << endl;
424 media_mgr.
close(media);
425 _pimpl->_medias.erase(media_nr);
433 DBG <<
"Don't know, let's ABORT" << endl;
446 ProvideFileOptions options )
452 provide( std::ref(op), resource, options );
456 provide( std::ref(op), resource, options );
462 if (
_pimpl->_medias.find( medianr ) !=
_pimpl->_medias.end() )
464 return _pimpl->_medias[medianr];
467 std::vector<media::MediaUrl> urls =
_pimpl->_urls;
469 for (
auto &url : urls ) {
470 url.setUrl (
rewriteUrl (url.url(), medianr) );
475 _pimpl->_medias[medianr] = id;
479 if (
_pimpl->_verifiers.find(medianr) !=
_pimpl->_verifiers.end() )
487 _pimpl->_verifiers.erase( medianr );
493 WAR <<
"Verifier not found" << endl;
503 if (scheme ==
"cd" || scheme ==
"dvd")
506 DBG <<
"Rewriting url " << url_r << endl;
522 DBG <<
"Url rewrite result: " << url << endl;
536 DBG <<
"Url rewrite result: " << url << endl;
545 DBG <<
"Releasing all media IDs held by this MediaSetAccess" << endl;
547 for (
auto m =
_pimpl->_medias.begin(); m !=
_pimpl->_medias.end(); ++m )
548 manager.
release(m->second,
"");
553 str <<
"MediaSetAccess (URL='" <<
_pimpl->_urls.at(0) <<
"', attach_point_hint='" <<
_pimpl->_prefAttachPoint <<
"')";
std::string getScheme() const
Returns the scheme name of the URL.
void setQueryParam(const std::string ¶m, const std::string &value)
Set or add value for the specified query parameter.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
String related utilities and Regular expression matching.
void operator()(media::MediaAccessId media, const OnMediaLocation &file)
ProvideFileExistenceOperation()
std::list< DirEntry > DirContent
Returned by readdir.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Do not differentiate case.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
const std::string & asString() const
String representation.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
IMPL_PTR_TYPE(Application)
void operator()(media::MediaAccessId media, const OnMediaLocation &file)
std::string numstring(char n, int w=0)
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Regular expression match result.
Base class for Exception.
void operator()(media::MediaAccessId media, const OnMediaLocation &file)
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Wrapper for const correct access via Smart pointer types.
bool regex_match(const std::string &s, smatch &matches, const regex ®ex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
void operator()(media::MediaAccessId media, const OnMediaLocation &file)
Easy-to use interface to the ZYPP dependency resolver.
static ManagedFile asManagedFile()
Create a temporary file and convert it to a automatically cleaned up ManagedFile. ...