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;
57 , _mirrors(
std::move( mirrors ) )
58 , _spec(
std::move( mediaSpec ))
59 , _parent(
std::move( parentRef ))
60 , _localPath( locPath )
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();
163 : _res(
std::move(file) )
164 , _provideHandle(
std::move (hdl) )
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() ) {
205 return attachMedia( std::vector<zypp::Url>{url}, request );
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,
"/" );
248 auto attachInfo = AttachedSyncMediaInfo_Ptr(
new AttachedSyncMediaInfo( shared_this<MediaSyncFacade>(), *attachId, useableUrls.front(), useableUrls, request, locPath ) );
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) {
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 () )
419 return prepareMedia( std::vector<zypp::Url>{url}, request );
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 ) {
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() )
519 |
and_then([weakMe = weak_this<MediaSyncFacade>(), fName = fileName, req = request ](
MediaHandle handle ){
520 auto me = weakMe.lock();
523 return me->provide( handle, fName, req);
544 if ( !sourcePi.isExist() ) {
547 if ( !sourcePi.isFile () )
583 ERR <<
"Releasing unknown medium " << ptr->
mediaId () <<
" should not happen";
IMPL_PTR_TYPE(AttachedSyncMediaInfo)
ZYPP_IMPL_PRIVATE_CONSTR(Context)
unsigned int devMinor() const
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
zypp::OnMediaLocation asOnMediaLocation(const zypp::Pathname &path, unsigned int mediaNr) const
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
bool empty() const
Test for an empty path.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
const std::string & asString() const
String representation.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Base class for reference counted objects.
int unlink(const Pathname &path)
Like 'unlink'.
static expected success(ConsParams &&...params)
void remove_if(LockSet &lockset_r, TPredicate pred_r)
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Base class for Exception.
bool any_of(const Container &c, Fnc &&cb)
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
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.
A "struct mntent" like mount entry structure, but using std::strings.
unsigned int devMajor() const
Wrapper class for ::stat/::lstat.
ResultType and_then(const expected< T, E > &exp, Function &&f)
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
bool checkExistsOnly() const
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.