16#include <zypp-media/ng/ProvideSpec>
32 const std::vector<zypp::Url> &
mirrors()
const;
33 const std::optional<zypp::Pathname> &
rootPath()
const;
34 MediaSyncFacadeRef
parent()
const;
43 void unref_to(
unsigned int)
const override;
64 _mirrors.push_back ( baseUrl );
66 auto i = std::find( _mirrors.begin(), _mirrors.end(), baseUrl );
67 if ( i != _mirrors.begin() ) {
68 if ( i != _mirrors.end() )
70 _mirrors.insert( _mirrors.begin(), baseUrl );
119 _parent->releaseMedium (
this );
133 return _data->parent();
138 return _data.get() !=
nullptr;
145 return invalidHandle;
146 return _data->mirrors().at(0);
151 static std::optional<zypp::Pathname> invalidPath;
154 return _data->rootPath();
175 std::vector<zypp::Url> usableMirrs;
176 std::optional<zypp::media::MediaHandlerFactory::MediaHandlerType> handlerType;
178 for (
auto mirrIt = urls.begin() ; mirrIt != urls.end(); mirrIt++ ) {
181 WAR <<
"URL: " << *mirrIt <<
" is not supported, ignoring!" << std::endl;
184 if ( !handlerType ) {
186 usableMirrs.push_back ( *mirrIt );
188 if ( handlerType == *s) {
189 usableMirrs.push_back( *mirrIt );
191 WAR <<
"URL: " << *mirrIt <<
" has different handler type than the primary URL: "<< usableMirrs.front() <<
", ignoring!" << std::endl;
196 if ( !handlerType || usableMirrs.empty() ) {
211 std::vector<zypp::Url> useableUrls =
sanitizeUrls(urls);
213 if ( useableUrls.empty () )
221 return medium->isSameMedium( useableUrls, request );
228 bool isVolatile = useableUrls.front().schemeIsVolatile();
230 std::optional<zypp::media::MediaAccessId> attachId;
238 attachId = mgr.
open(
zyppng::transform ( useableUrls, [](
const auto &u) {
return zypp::media::MediaUrl(u); } ) );
247 auto locPath = mgr.
localPath( *attachId,
"/" );
274 unsigned int devindex = 0;
276 std::vector<std::string> devices;
279 std::optional<std::string> currentlyUsed;
280 if ( devices.size() ) currentlyUsed = devices[devindex];
285 devices.erase( std::remove_if( devices.begin (), devices.end(), [&](
const std::string &dev) {
286 zypp::PathInfo devInfo(dev);
287 return std::any_of( mountedDevs.begin (), mountedDevs.end(), [&devInfo]( const zypp::media::MountEntry &e ) {
288 zypp::PathInfo pi( e.src );
289 return ( pi.isBlk() && pi.devMajor() == devInfo.devMajor() && pi.devMinor() == devInfo.devMinor() );
293 if ( !devices.size () ) {
295 MIL <<
"No free device available, return jammed and try again later ( hopefully) " << std::endl;
296 if ( attachId ) mgr.
close ( *attachId );
301 bool foundCurrent =
false;
302 if ( currentlyUsed ) {
303 for (
unsigned int i = 0; i < devices.size(); i++ ) {
304 if ( devices[i] == *currentlyUsed ) {
312 if ( !foundCurrent ){
317 zypp::Url effectiveUrl = useableUrls.front();
319 user = report->requestMedia (
329 MIL <<
"ProvideFile exception caught, callback answer: " << user << std::endl;
333 DBG <<
"Aborting" << std::endl;
334 if ( attachId ) mgr.
close ( *attachId );
335 zypp::AbortRequestException aexcp(
"Aborting requested by user");
336 aexcp.remember(excp);
340 DBG <<
"Skipping" << std::endl;
341 if ( attachId ) mgr.
close ( *attachId );
342 zypp::SkipRequestException nexcp(
"User-requested skipping of a file");
343 nexcp.remember(excp);
347 DBG <<
"Eject: try to release" << std::endl;
352 mgr.
release (*attachId, devindex < devices.size() ? devices[devindex] :
"");
363 DBG <<
"Going to try again" << std::endl;
367 mgr.
close(*attachId);
372 if ( useableUrls.front() != effectiveUrl ) {
373 useableUrls.clear ();
374 useableUrls.push_back ( effectiveUrl );
382 DBG <<
"Don't know, let's ABORT" << std::endl;
383 if ( attachId ) mgr.
close ( *attachId );
390 if ( attachId ) mgr.
close ( *attachId );
394 if ( attachId ) mgr.
close ( *attachId );
405 WAR <<
"Releasing zyppng::MediaSyncFacade with still valid MediaHandles, this is a bug!" << std::endl;
412 if ( useableUrls.empty () )
428 MIL <<
"Attaching lazy medium with label: [" << lazyHandle.
spec().
label() <<
"]" << std::endl;
444 std::optional<expected<MediaSyncFacade::Res>> lastErr;
445 for (
const zypp::Url& file_url : urls ) {
449 url.setPathName (
"/");
469 url.setPathName (
"/");
476 return provide( std::vector<zypp::Url>{
url}, request );
482 const auto &handleInfo = attachHandle.
info();
486 if ( !mgr.
doesFileExist ( handleInfo.mediaId (), fileName ) ) {
501 if ( handleInfo.url().schemeIsDownloading() )
520 auto me = weakMe.lock();
523 return me->provide( handle, fName, req);
541 url.setPathName( source );
544 if ( !sourcePi.isExist() ) {
547 if ( !sourcePi.isFile () )
583 ERR <<
"Releasing unknown medium " << ptr->
mediaId () <<
" should not happen";
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
Base class for Exception.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Base class for reference counted objects.
Wrapper class for stat/lstat.
bool empty() const
Test for an empty path.
std::shared_ptr< T > shared_this() const
std::weak_ptr< T > weak_this() const
zypp::OnMediaLocation asOnMediaLocation(const zypp::Pathname &path, unsigned int mediaNr) const
bool checkExistsOnly() const
static expected success(ConsParams &&...params)
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
int unlink(const Pathname &path)
Like 'unlink'.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
ResultType and_then(const expected< T, E > &exp, Function &&f)
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
#define IMPL_PTR_TYPE(NAME)
#define ZYPP_IMPL_PRIVATE_CONSTR(Class)