libzypp: zypp/ng/media/provide.cc Source File

libzypp 17.38.8

provide.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "provide.h"
10
11#include <utility>
12#include <zypp-core/TriBool.h>
13#include <zypp-core/base/userrequestexception.h>
14#include <zypp-media/mount.h>
15#include <zypp-media/ng/ProvideSpec>
16
17#include <zypp/ZYppCallbacks.h>
18#include <zypp/MediaSetAccess.h>
19#include <zypp/media/MediaHandlerFactory.h>
20#include <zypp/repo/SUSEMediaVerifier.h>
21
22namespace zyppng {
23
24 class AttachedMediaInfo : public zypp::base::ReferenceCounted, private zypp::base::NonCopyable
25 {
26
27 public:
28
29 AttachedMediaInfo( ProvideRef parentRef, zypp::media::MediaAccessId mediaId, zypp::MirroredOrigin origin, ProvideMediaSpec mediaSpec, const zypp::Pathname &locPath );
30
31 zypp::media::MediaAccessId mediaId () const;
32 const ProvideMediaSpec &spec() const;
33 zypp::Url url() const;
34 const zypp::MirroredOrigin &origin() const;
35 const std::optional<zypp::Pathname> &rootPath() const;
36 ProvideRef parent() const;
37
41 bool isSameMedium ( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &spec );
42
43 // ReferenceCounted interface
44 protected:
45 void unref_to(unsigned int) const override;
46
47 private:
48 zypp::media::MediaAccessId _id;
49 zypp::MirroredOrigin _origin;
50 ProvideMediaSpec _spec;
51 ProvideRef _parent;
52 std::optional<zypp::Pathname> _localPath;
53 };
54
55 IMPL_PTR_TYPE( AttachedMediaInfo );
56
57 AttachedMediaInfo::AttachedMediaInfo(ProvideRef parentRef, zypp::media::MediaAccessId mediaId, zypp::MirroredOrigin origin, ProvideMediaSpec mediaSpec, const zypp::Pathname &locPath)
58 : _id( mediaId )
59 , _origin( std::move( origin ) )
60 , _spec(std::move( mediaSpec ))
61 , _parent(std::move( parentRef ))
62 , _localPath( locPath )
63 {}
64
65 zypp::media::MediaAccessId AttachedMediaInfo::mediaId() const
66 {
67 return _id;
68 }
69
70 const ProvideMediaSpec &AttachedMediaInfo::spec() const
71 {
72 return _spec;
73 }
74
75 zypp::Url AttachedMediaInfo::url() const
76 {
77 return _origin.authorities()[0].url();
78 }
79
80 const zypp::MirroredOrigin &AttachedMediaInfo::origin() const
81 {
82 return _origin;
83 }
84
85 const std::optional<zypp::Pathname> &AttachedMediaInfo::rootPath() const
86 {
87 return _localPath;
88 }
89
90 ProvideRef AttachedMediaInfo::parent() const
91 {
92 return _parent;
93 }
94
95 bool AttachedMediaInfo::isSameMedium(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &spec)
96 {
97 return ProvideMediaSpec::isSameMedium ( _origin, _spec, origin, spec );
98 }
99
100 void AttachedMediaInfo::unref_to( unsigned int count ) const
101 {
102 // once count reaches 1 only the Provide holds a reference,
103 // time to release the medium
104 if ( count == 1 ) {
105 _parent->releaseMedium ( this );
106 // !!!! careful from here on out 'this' is most likely invalid !!!!
107 return;
108 }
109 }
110
111
112 ProvideMediaHandle::ProvideMediaHandle(){ }
113
114 ProvideMediaHandle::ProvideMediaHandle(AttachedMediaInfo_Ptr dataPtr) : _data( std::move(dataPtr) )
115 { }
116
117 ProvideRef ProvideMediaHandle::parent() const
118 {
119 return _data->parent();
120 }
121
122 bool ProvideMediaHandle::isValid() const
123 {
124 return _data.get() != nullptr;
125 }
126
127 const zypp::Url &ProvideMediaHandle::baseUrl() const
128 {
129 static zypp::Url invalidHandle;
130 if ( !_data ) return invalidHandle;
131 return _data->origin().authorities()[0].url();
132 }
133
134 const std::optional<zypp::Pathname> &ProvideMediaHandle::localPath() const
135 {
136 static std::optional<zypp::Pathname> invalidPath;
137 if ( !_data )
138 return invalidPath;
139 return _data->rootPath();
140 }
141
142 const AttachedMediaInfo &ProvideMediaHandle::info() const
143 {
144 return *_data;
145 }
146
147 ProvideRes::ProvideRes(ProvideMediaHandle hdl, zypp::ManagedFile file)
148 : _res( std::move(file) )
149 , _provideHandle( std::move (hdl) )
150 { }
151
152 const zypp::Pathname ProvideRes::file() const {
153 return _res;
154 }
155
156 ZYPP_IMPL_PRIVATE_CONSTR (Provide) { }
157
158 zypp::MirroredOrigin Provide::sanitizeUrls( const zypp::MirroredOrigin &origin ) const
159 {
160 const auto &handlerType = zypp::media::MediaHandlerFactory::handlerType ( origin.authorities()[0].url() );
161 if ( !handlerType ) {
162 ERR << "Authority URL: " << origin.authorities()[0] << " is not supported!" << std::endl;
163 return {};
164 }
165
166 zypp::MirroredOrigin sanitized( origin.authorities()[0] );
167 for ( const auto &mirror : origin.mirrors() ) {
168 const auto &s = zypp::media::MediaHandlerFactory::handlerType ( mirror.url() );
169 if ( !s ) {
170 WAR << "URL: " << mirror << " is not supported, ignoring!" << std::endl;
171 continue;
172 }
173 if ( handlerType == *s) {
174 sanitized.addMirror(mirror);
175 } else {
176 WAR << "URL: " << mirror << " has different handler type than the authority URL: "<< origin.authorities()[0] <<", ignoring!" << std::endl;
177 }
178 }
179
180 return sanitized;
181 }
182
183 expected<Provide::MediaHandle> Provide::attachMedia( const zypp::Url &url, const ProvideMediaSpec &request )
184 {
185 return attachMedia( zypp::MirroredOrigin{url}, request );
186 }
187
188 expected<Provide::MediaHandle> Provide::attachMedia( const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request )
189 {
190 // rewrite and sanitize the urls if required
191 zypp::MirroredOrigin sanitizedOrigin = sanitizeUrls(origin);
192
193 if ( !sanitizedOrigin.isValid() )
194 return expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("No valid mirrors available") ));
195
196 if ( request.medianr() > 1 ) {
197 for ( auto &ep : sanitizedOrigin )
198 ep.url() = zypp::MediaSetAccess::rewriteUrl( ep.url(), request.medianr() );
199 }
200
201 // first try and find a already attached medium
202 auto i = std::find_if( _attachedMedia.begin (), _attachedMedia.end(), [&]( const AttachedMediaInfo_Ptr &medium ) {
203 return medium->isSameMedium( sanitizedOrigin, request );
204 });
205
206 if ( i != _attachedMedia.end() ) {
207 return expected<Provide::MediaHandle>::success( *i );
208 }
209
210 bool isVolatile = sanitizedOrigin.authorities()[0].url().schemeIsVolatile();
211
212 std::optional<zypp::media::MediaAccessId> attachId;
213 zypp::callback::SendReport<zypp::media::MediaChangeReport> report;
214
215 // nothing attached, make a new one
216 zypp::media::MediaManager mgr;
217 do {
218 try {
219 if ( !attachId ) {
220 attachId = mgr.open( sanitizedOrigin );
221 if ( !request.mediaFile().empty() ) {
222 mgr.addVerifier( *attachId, zypp::media::MediaVerifierRef( new zypp::repo::SUSEMediaVerifier( request.mediaFile(), request.medianr() ) ) );
223 }
224 }
225
226 // attach the medium
227 mgr.attach( *attachId );
228
229 auto locPath = mgr.localPath( *attachId, "/" );
230 auto attachInfo = AttachedMediaInfo_Ptr( new AttachedMediaInfo( shared_this<Provide>(), *attachId, std::move(sanitizedOrigin), request, locPath ) );
231 _attachedMedia.push_back( attachInfo );
232 return expected<Provide::MediaHandle>::success( std::move(attachInfo) );
233
234 } catch ( const zypp::media::MediaException &excp ) {
235
236 ZYPP_CAUGHT(excp);
237
238 // if no one is listening, just return the error as is
239 if ( !zypp::callback::SendReport<zypp::media::MediaChangeReport>::connected() || !attachId ) {
240 return expected<Provide::MediaHandle>::error( ZYPP_FWD_CURRENT_EXCPT() );
241 }
242
243 // default action is to cancel
244 zypp::media::MediaChangeReport::Action user = zypp::media::MediaChangeReport::ABORT;
245
246 do {
247 // here: Manager tried all not attached drives and could not find the desired medium
248 // we need to send the media change report
249
250 // set up the reason
251 auto reason = zypp::media::MediaChangeReport::INVALID;
252 if( typeid(excp) == typeid( zypp::media::MediaNotDesiredException) ) {
253 reason = zypp::media::MediaChangeReport::WRONG;
254 }
255
256 unsigned int devindex = 0;
257
258 std::vector<std::string> devices;
259 mgr.getDetectedDevices(*attachId, devices, devindex);
260
261 std::optional<std::string> currentlyUsed;
262 if ( devices.size() ) currentlyUsed = devices[devindex];
263
264 if ( isVolatile ) {
265 // filter devices that are mounted, aka used, we can not eject them
266 const auto &mountedDevs = zypp::media::Mount::getEntries();
267 devices.erase( std::remove_if( devices.begin (), devices.end(), [&](const std::string &dev) {
268 zypp::PathInfo devInfo(dev);
269 return std::any_of( mountedDevs.begin (), mountedDevs.end(), [&devInfo]( const zypp::media::MountEntry &e ) {
270 zypp::PathInfo pi( e.src );
271 return ( pi.isBlk() && pi.devMajor() == devInfo.devMajor() && pi.devMinor() == devInfo.devMinor() );
272 });
273 }), devices.end() );
274
275 if ( !devices.size () ) {
276 // Jammed, no currently free device
277 MIL << "No free device available, return jammed and try again later ( hopefully) " << std::endl;
278 if ( attachId ) mgr.close ( *attachId );
279 return expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR(zypp::media::MediaJammedException()) );
280 }
281
282 // update index to currenty used dev
283 bool foundCurrent = false;
284 if ( currentlyUsed ) {
285 for ( unsigned int i = 0; i < devices.size(); i++ ) {
286 if ( devices[i] == *currentlyUsed ) {
287 foundCurrent = true;
288 devindex = i;
289 break;
290 }
291 }
292 }
293
294 if ( !foundCurrent ){
295 devindex = 0; // seems 0 is what is set in the handlers too if there is no current
296 }
297 }
298
299 zypp::Url effectiveUrl = sanitizedOrigin.authorities()[0].url();
300
301 user = report->requestMedia (
302 effectiveUrl,
303 request.medianr(),
304 request.label(),
305 reason,
306 excp.asUserHistory(),
307 devices,
308 devindex
309 );
310
311 MIL << "ProvideFile exception caught, callback answer: " << user << std::endl;
312
313 switch ( user ) {
314 case zypp::media::MediaChangeReport::ABORT: {
315 DBG << "Aborting" << std::endl;
316 if ( attachId ) mgr.close ( *attachId );
317 zypp::AbortRequestException aexcp("Aborting requested by user");
318 aexcp.remember(excp);
319 return expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR(aexcp) );
320 }
321 case zypp::media::MediaChangeReport::IGNORE: {
322 DBG << "Skipping" << std::endl;
323 if ( attachId ) mgr.close ( *attachId );
324 zypp::SkipRequestException nexcp("User-requested skipping of a file");
325 nexcp.remember(excp);
326 return expected<Provide::MediaHandle>::error( ZYPP_EXCPT_PTR(nexcp) );
327 }
328 case zypp::media::MediaChangeReport::EJECT: {
329 DBG << "Eject: try to release" << std::endl;
330 try
331 {
332 // MediaSetAccess does a releaseAll, but we can not release other devices that are in use
333 // media_mgr.releaseAll();
334 mgr.release (*attachId, devindex < devices.size() ? devices[devindex] : "");
335 }
336 catch ( const zypp::Exception & e)
337 {
338 ZYPP_CAUGHT(e);
339 }
340 break;
341 }
342 case zypp::media::MediaChangeReport::RETRY:
343 case zypp::media::MediaChangeReport::CHANGE_URL: {
344 // retry
345 DBG << "Going to try again" << std::endl;
346
347 // invalidate current media access id
348 if ( attachId ) {
349 mgr.close(*attachId);
350 attachId.reset();
351 }
352
353 // explicitely setting a URL from the callback wipes all mirrors
354 if ( sanitizedOrigin.authorities()[0].url() != effectiveUrl ) {
355 sanitizedOrigin.clearMirrors ();
356 sanitizedOrigin.setAuthority ( effectiveUrl );
357 }
358
359 // not attaching, media set will do that for us
360 // this could generate uncaught exception (#158620)
361 break;
362 }
363 default: {
364 DBG << "Don't know, let's ABORT" << std::endl;
365 if ( attachId ) mgr.close ( *attachId );
366 return expected<Provide::MediaHandle>::error( ZYPP_FWD_CURRENT_EXCPT() );
367 }
368 }
369 } while( user == zypp::media::MediaChangeReport::EJECT );
370 } catch ( const zypp::Exception &e ) {
371 ZYPP_CAUGHT(e);
372 if ( attachId ) mgr.close ( *attachId );
373 return expected<Provide::MediaHandle>::error( ZYPP_FWD_CURRENT_EXCPT() );
374 } catch (...) {
375 // didn't work -> clean up
376 if ( attachId ) mgr.close ( *attachId );
377 return expected<Provide::MediaHandle>::error( ZYPP_FWD_CURRENT_EXCPT() );
378 }
379 } while ( true );
380 }
381
382 zyppng::Provide::~Provide()
383 {
384 // this should never happen because every handle has a reference to the media manager, but still add a debug output
385 // so we know in case we have weird behavior.
386 if ( _attachedMedia.size () ) {
387 WAR << "Releasing zyppng::Provide with still valid MediaHandles, this is a bug!" << std::endl;
388 }
389 }
390
391 expected<Provide::LazyMediaHandle> Provide::prepareMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
392 {
393 const auto &sanitizedOrigin = sanitizeUrls(origin);
394 if ( !sanitizedOrigin.isValid() )
395 return expected<Provide::LazyMediaHandle>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("No valid mirrors available") ));
396 return expected<LazyMediaHandle>::success( shared_this<Provide>(), std::move(sanitizedOrigin), request );
397 }
398
399 expected<Provide::LazyMediaHandle> Provide::prepareMedia(const zypp::Url &url, const ProvideMediaSpec &request)
400 {
401 return prepareMedia( zypp::MirroredOrigin{url}, request );
402 }
403
404 expected<Provide::MediaHandle> Provide::attachMediaIfNeeded( LazyMediaHandle lazyHandle)
405 {
406 using namespace zyppng::operators;
407 if ( lazyHandle.attached() )
408 return expected<MediaHandle>::success( *lazyHandle.handle() );
409
410 MIL << "Attaching lazy medium with label: [" << lazyHandle.spec().label() << "]" << std::endl;
411
412 return attachMedia( lazyHandle.origin(), lazyHandle.spec () )
413 | and_then([lazyHandle]( MediaHandle handle ) {
414 lazyHandle._sharedData->_mediaHandle = handle;
415 return expected<MediaHandle>::success( std::move(handle) );
416 });
417 }
418
419 expected<ProvideRes> Provide::provide(const zypp::MirroredOrigin &origin, const ProvideFileSpec &request)
420 {
421 using namespace zyppng::operators;
422
423 if ( !origin.isValid() )
424 return expected<ProvideRes>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaException("Can not provide a file without a URL.") ));
425
426 std::optional<expected<ProvideRes>> lastErr;
427 for ( const zypp::OriginEndpoint& file_url : origin ) {
428
429 zypp::OriginEndpoint ep(file_url);
430 zypp::Pathname fileName(ep.url().getPathName());
431 ep.url().setPathName ("/");
432
433 expected<ProvideRes> res = attachMedia( zypp::MirroredOrigin(ep), ProvideMediaSpec( "" ) )
434 | and_then( [&, this]( const Provide::MediaHandle& handle ) {
435 return provide( handle, fileName, request.asOnMediaLocation(fileName, 1));
436 });
437
438 if ( res )
439 return res;
440
441 lastErr = res;
442 }
443
444 // we always should have a last error, except if the URLs are empty
445 if ( lastErr )
446 return *lastErr;
447
448 // we should not get here, but if we do simply use the first entry to make a not found error
449 zypp::Url url( origin.authorities()[0].url() );
450 zypp::Pathname fileName(url.getPathName());
451 url.setPathName ("/");
452 return expected<ProvideRes>::error( ZYPP_EXCPT_PTR ( zypp::media::MediaFileNotFoundException( url, fileName )));
453
454 }
455
456 expected<ProvideRes> Provide::provide(const zypp::Url &url, const ProvideFileSpec &request)
457 {
458 return provide( zypp::MirroredOrigin{url}, request );
459 }
460
461 expected<ProvideRes> Provide::provide(const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request)
462 {
463 zypp::media::MediaManager mgr;
464 const auto &handleInfo = attachHandle.info();
465
466 try {
467 if ( request.checkExistsOnly() ) {
468 if ( !mgr.doesFileExist ( handleInfo.mediaId (), fileName ) ) {
469 return expected<ProvideRes>::error( ZYPP_EXCPT_PTR( zypp::media::MediaFileNotFoundException( handleInfo.url(), fileName ) ) );
470 }
471
472 // we return a result pointing to a non existant file, since the code just asked us to check if the file exists
473 return expected<ProvideRes>::success( attachHandle, zypp::ManagedFile( mgr.localPath( handleInfo.mediaId(), fileName ) ) );
474
475 } else {
476 mgr.provideFile( handleInfo.mediaId (), request.asOnMediaLocation( fileName, handleInfo.spec().medianr()) );
477
478 zypp::ManagedFile locFile( mgr.localPath( handleInfo.mediaId(), fileName ) );
479
480 // do not clean up files for now, they are cleaned up anyways on detach
481#if 0
482 // if the file is downloaded we want to clean it up again
483 if ( handleInfo.url().schemeIsDownloading() )
484 locFile.setDispose ( zypp::filesystem::unlink );
485#endif
486
487 return expected<ProvideRes>::success( attachHandle, locFile );
488 }
489 } catch ( const zypp::Exception &e ) {
490 ZYPP_CAUGHT(e);
491 return expected<ProvideRes>::error(ZYPP_FWD_CURRENT_EXCPT());
492 } catch (...) {
493 return expected<ProvideRes>::error(ZYPP_FWD_CURRENT_EXCPT());
494 }
495 }
496
497 expected<ProvideRes> Provide::provide( const LazyMediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request )
498 {
499 using namespace zyppng::operators;
500 return attachMediaIfNeeded ( attachHandle )
501 | and_then([weakMe = weak_this<Provide>(), fName = fileName, req = request ]( MediaHandle handle ){
502 auto me = weakMe.lock();
503 if ( !me )
504 return expected<Res>::error(ZYPP_EXCPT_PTR(zypp::Exception("Provide was released during a operation")));
505 return me->provide( handle, fName, req);
506 });
507 }
508
509 zyppng::expected<zypp::CheckSum> Provide::checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
510 {
511 try {
512 return expected<zypp::CheckSum>::success( zypp::CheckSum( algorithm, zypp::filesystem::checksum ( p, algorithm ) ) );
513 } catch(...) {
514 return expected<zypp::CheckSum>::error ( std::current_exception () );
515 }
516 }
517
518 expected<zypp::ManagedFile> Provide::copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
519 {
520 try {
521 // do what Provide would do and make a URL
522 zypp::Url url("copy:///");
523 url.setPathName( source );
524
525 auto sourcePi = zypp::PathInfo(source);
526 if ( !sourcePi.isExist() ) {
527 return expected<zypp::ManagedFile>::error ( ZYPP_EXCPT_PTR( zypp::media::MediaFileNotFoundException( url, "" ) ) );
528 }
529 if ( !sourcePi.isFile () )
530 return expected<zypp::ManagedFile>::error ( ZYPP_EXCPT_PTR( zypp::media::MediaNotAFileException( url, "" ) ) );
531
532 auto res = zypp::filesystem::hardlinkCopy( source, target.asString() );
533 if ( res == 0 ) {
534 return expected<zypp::ManagedFile>::success( zypp::ManagedFile( target, zypp::filesystem::unlink ) );
535 } else {
536 return expected<zypp::ManagedFile>::error ( ZYPP_EXCPT_PTR( zypp::media::MediaException( zypp::str::Str() << "Failed to create file " << target << " errno: " << res ) ) );
537 }
538 } catch(...) {
539 return expected<zypp::ManagedFile>::error ( std::current_exception () );
540 }
541 }
542
543 expected<zypp::ManagedFile> Provide::copyFile(zyppng::ProvideRes source, const zypp::Pathname &target)
544 {
545 // not much to do here, since this will block until the file has been copied we do not need to remember the ProvideRes
546 return copyFile( source.file(), target );
547 }
548
549 void zyppng::Provide::releaseMedium(const AttachedMediaInfo *ptr)
550 {
551 if ( !ptr ) return;
552
553 auto i = std::find_if(_attachedMedia.begin (), _attachedMedia.end(), [&]( const auto &p ) { return p.get() == ptr; } );
554
555 try {
556 zypp::media::MediaManager mgr;
557 mgr.close ( ptr->mediaId() );
558 } catch ( const zypp::Exception & e ) {
559 ZYPP_CAUGHT(e);
560 }
561
562 if ( i != _attachedMedia.end() ) {
563 _attachedMedia.erase(i);
564 } else {
565 ERR << "Releasing unknown medium " << ptr->mediaId () << " should not happen";
566 }
567 }
568
569
570}
ZYPP_CAUGHT
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
ZYPP_EXCPT_PTR
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:463
ZYPP_FWD_CURRENT_EXCPT
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
Definition Exception.h:471
DBG
#define DBG
Definition Logger.h:102
MIL
#define MIL
Definition Logger.h:103
ERR
#define ERR
Definition Logger.h:105
WAR
#define WAR
Definition Logger.h:104
MediaHandlerFactory.h
MediaSetAccess.h
SUSEMediaVerifier.h
TriBool.h
ZYppCallbacks.h
zypp::AutoDispose::setDispose
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
Definition AutoDispose.h:167
zypp::CheckSum
Definition CheckSum.h:34
zypp::Exception
Base class for Exception.
Definition Exception.h:153
zypp::Exception::asUserHistory
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition Exception.cc:140
zypp::MediaSetAccess::rewriteUrl
static Url rewriteUrl(const Url &url_r, const media::MediaNr medianr)
Replaces media number in specified url with given medianr.
Definition MediaSetAccess.cc:500
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
zypp::MirroredOrigin::mirrors
const std::vector< OriginEndpoint > & mirrors() const
Definition MirroredOrigin.cc:214
zypp::MirroredOrigin::authorities
const std::vector< OriginEndpoint > & authorities() const
Definition MirroredOrigin.cc:200
zypp::MirroredOrigin::setAuthority
void setAuthority(OriginEndpoint newAuthority)
Definition MirroredOrigin.cc:170
zypp::MirroredOrigin::isValid
bool isValid() const
Definition MirroredOrigin.cc:219
zypp::MirroredOrigin::clearMirrors
void clearMirrors()
Definition MirroredOrigin.cc:292
zypp::MirroredOrigin::addMirror
bool addMirror(OriginEndpoint newMirror)
Definition MirroredOrigin.cc:252
zypp::OriginEndpoint
Represents a single, configurable network endpoint, combining a URL with specific access settings.
Definition MirroredOrigin.h:41
zypp::OriginEndpoint::url
const zypp::Url & url() const
Definition MirroredOrigin.cc:53
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::Url::getPathName
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition Url.cc:631
zypp::Url::setPathName
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition Url.cc:791
zypp::base::ReferenceCounted
Base class for reference counted objects.
Definition ReferenceCounted.h:35
zypp::filesystem::PathInfo
Wrapper class for stat/lstat.
Definition PathInfo.h:226
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition Pathname.h:117
zypp::media::MediaException
Just inherits Exception to separate media exceptions.
Definition mediaexception.h:37
zypp::media::MediaFileNotFoundException
Definition mediaexception.h:164
zypp::media::MediaHandlerFactory::handlerType
static std::optional< MediaHandlerType > handlerType(const Url &url)
Definition MediaHandlerFactory.cc:32
zypp::media::MediaJammedException
Definition mediaexception.h:118
zypp::media::MediaManager
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees,...
Definition MediaManager.h:454
zypp::media::MediaManager::open
MediaAccessId open(const Url &url, const Pathname &preferred_attach_point="")
Opens the media access for specified with the url.
Definition MediaManager.cc:318
zypp::media::MediaManager::attach
void attach(MediaAccessId accessId)
Attach the media using the concrete handler (checks all devices).
Definition MediaManager.cc:447
zypp::media::MediaManager::close
void close(MediaAccessId accessId)
Close the media access with specified id.
Definition MediaManager.cc:341
zypp::media::MediaManager::provideFile
ZYPP_DEPRECATED void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
Definition MediaManager.cc:707
zypp::media::MediaManager::release
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
Definition MediaManager.cc:516
zypp::media::MediaManager::doesFileExist
bool doesFileExist(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
Definition MediaManager.cc:856
zypp::media::MediaManager::localPath
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for 'localRoot() + pathname', but returns an empty pathname if media is not attached.
Definition MediaManager.cc:696
zypp::media::MediaManager::addVerifier
void addVerifier(MediaAccessId accessId, const MediaVerifierRef &verifier)
Add verifier implementation for the specified media id.
Definition MediaManager.cc:410
zypp::media::MediaManager::getDetectedDevices
void getDetectedDevices(MediaAccessId accessId, std::vector< std::string > &devices, unsigned int &index) const
Fill in a vector of detected ejectable devices and the index of the currently attached device within ...
Definition MediaManager.cc:868
zypp::media::MediaNotAFileException
Definition mediaexception.h:258
zypp::media::MediaNotDesiredException
Definition mediaexception.h:400
zypp::media::Mount::getEntries
static MountEntries getEntries(const std::string &mtab="")
Return mount entries from /etc/mtab or /etc/fstab file.
Definition mount.cc:169
zypp::repo::SUSEMediaVerifier
Implementation of the traditional SUSE media verifier.
Definition SUSEMediaVerifier.h:28
zyppng::AttachedMediaInfo
Definition provide.cc:25
zyppng::AttachedMediaInfo::AttachedMediaInfo
AttachedMediaInfo(ProvideRef parentRef, zypp::media::MediaAccessId mediaId, zypp::MirroredOrigin origin, ProvideMediaSpec mediaSpec, const zypp::Pathname &locPath)
Definition provide.cc:57
zyppng::AttachedMediaInfo::_spec
ProvideMediaSpec _spec
Definition provide.cc:50
zyppng::AttachedMediaInfo::unref_to
void unref_to(unsigned int) const override
Definition provide.cc:100
zyppng::AttachedMediaInfo::rootPath
const std::optional< zypp::Pathname > & rootPath() const
Definition provide.cc:85
zyppng::AttachedMediaInfo::isSameMedium
bool isSameMedium(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &spec)
Definition provide.cc:95
zyppng::AttachedMediaInfo::origin
const zypp::MirroredOrigin & origin() const
Definition provide.cc:80
zyppng::AttachedMediaInfo::url
zypp::Url url() const
Definition provide.cc:75
zyppng::AttachedMediaInfo::_localPath
std::optional< zypp::Pathname > _localPath
Definition provide.cc:52
zyppng::AttachedMediaInfo::_parent
ProvideRef _parent
Definition provide.cc:51
zyppng::AttachedMediaInfo::spec
const ProvideMediaSpec & spec() const
Definition provide.cc:70
zyppng::AttachedMediaInfo::_id
zypp::media::MediaAccessId _id
Definition provide.cc:48
zyppng::AttachedMediaInfo::_origin
zypp::MirroredOrigin _origin
Definition provide.cc:49
zyppng::AttachedMediaInfo::parent
ProvideRef parent() const
Definition provide.cc:90
zyppng::AttachedMediaInfo::mediaId
zypp::media::MediaAccessId mediaId() const
Definition provide.cc:65
zyppng::Base::shared_this
std::shared_ptr< T > shared_this() const
Definition base.h:114
zyppng::Base::weak_this
std::weak_ptr< T > weak_this() const
Definition base.h:124
zyppng::LazyMediaHandle::origin
const zypp::MirroredOrigin & origin() const
Definition lazymediahandle.h:57
zyppng::LazyMediaHandle::_sharedData
Ref< Data > _sharedData
Definition lazymediahandle.h:99
zyppng::LazyMediaHandle::spec
const ProvideMediaSpec & spec() const
Definition lazymediahandle.h:65
zyppng::LazyMediaHandle::attached
bool attached() const
Definition lazymediahandle.h:77
zyppng::LazyMediaHandle::handle
std::optional< MediaHandle > handle() const
Definition lazymediahandle.h:61
zyppng::ProvideFileSpec
Definition providespec.h:95
zyppng::ProvideFileSpec::asOnMediaLocation
zypp::OnMediaLocation asOnMediaLocation(const zypp::Pathname &path, unsigned int mediaNr) const
Definition providespec.cc:296
zyppng::ProvideFileSpec::checkExistsOnly
bool checkExistsOnly() const
Definition providespec.cc:218
zyppng::ProvideMediaHandle
Definition provide.h:27
zyppng::ProvideMediaHandle::baseUrl
const zypp::Url & baseUrl() const
Definition provide.cc:127
zyppng::ProvideMediaHandle::isValid
bool isValid() const
Definition provide.cc:122
zyppng::ProvideMediaHandle::localPath
const std::optional< zypp::Pathname > & localPath() const
Definition provide.cc:134
zyppng::ProvideMediaHandle::parent
ProvideRef parent() const
Definition provide.cc:117
zyppng::ProvideMediaHandle::info
const AttachedMediaInfo & info() const
Definition provide.cc:142
zyppng::ProvideMediaHandle::_data
AttachedMediaInfo_Ptr _data
Definition provide.h:41
zyppng::ProvideMediaHandle::ProvideMediaHandle
ProvideMediaHandle()
Definition provide.cc:112
zyppng::ProvideMediaSpec
Definition providespec.h:30
zyppng::ProvideMediaSpec::isSameMedium
zypp::TriBool isSameMedium(const ProvideMediaSpec &other) const
Definition providespec.cc:146
zyppng::ProvideMediaSpec::medianr
unsigned medianr() const
Definition providespec.cc:110
zyppng::ProvideMediaSpec::mediaFile
zypp::Pathname mediaFile() const
Definition providespec.cc:119
zyppng::ProvideMediaSpec::label
const std::string & label() const
Definition providespec.cc:101
zyppng::ProvideRes
Definition provide.h:44
zyppng::ProvideRes::ProvideRes
ProvideRes(ProvideMediaHandle hdl, zypp::ManagedFile file)
Definition provide.cc:147
zyppng::ProvideRes::file
const zypp::Pathname file() const
Definition provide.cc:152
zyppng::ProvideRes::_provideHandle
ProvideMediaHandle _provideHandle
Definition provide.h:92
zyppng::ProvideRes::_res
zypp::ManagedFile _res
Definition provide.h:91
zyppng::Provide
Definition provide.h:103
zyppng::Provide::checksumForFile
expected< zypp::CheckSum > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
Definition provide.cc:509
zyppng::Provide::sanitizeUrls
zypp::MirroredOrigin sanitizeUrls(const zypp::MirroredOrigin &origin) const
Definition provide.cc:158
zyppng::Provide::attachMedia
expected< MediaHandle > attachMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
Definition provide.cc:188
zyppng::Provide::prepareMedia
expected< LazyMediaHandle > prepareMedia(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &request)
Definition provide.cc:391
zyppng::Provide::AttachedMediaInfo
friend class AttachedMediaInfo
Definition provide.h:107
zyppng::Provide::copyFile
expected< zypp::ManagedFile > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
Definition provide.cc:518
zyppng::Provide::provide
expected< Res > provide(const zypp::MirroredOrigin &origin, const ProvideFileSpec &request)
Definition provide.cc:419
zyppng::Provide::LazyMediaHandle
::zyppng::LazyMediaHandle< Provide > LazyMediaHandle
Definition provide.h:110
zyppng::Provide::_attachedMedia
std::vector< AttachedMediaInfo_Ptr > _attachedMedia
Definition provide.h:151
zyppng::Provide::~Provide
~Provide() override
Definition provide.cc:382
zyppng::Provide::attachMediaIfNeeded
expected< MediaHandle > attachMediaIfNeeded(LazyMediaHandle lazyHandle)
Definition provide.cc:404
zyppng::Provide::releaseMedium
void releaseMedium(const AttachedMediaInfo *ptr)
Definition provide.cc:549
zyppng::Provide::MediaHandle
ProvideMediaHandle MediaHandle
Definition provide.h:109
zyppng::expected
Definition expected.h:56
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:178
zyppng::expected::error
E & error()
Definition expected.h:288
mount.h
std
Definition ansi.h:855
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition NonCopyable.h:26
zypp::filesystem::checksum
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
Definition PathInfo.cc:1070
zypp::filesystem::hardlinkCopy
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
Definition PathInfo.cc:902
zypp::filesystem::unlink
int unlink(const Pathname &path)
Like 'unlink'.
Definition PathInfo.cc:719
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition MediaSource.h:30
zypp::media::MediaVerifierRef
zypp::RW_pointer< MediaVerifierBase > MediaVerifierRef
A shared reference to the MediaVerifier implementation.
Definition MediaManager.h:107
zypp::target
Definition KeyRing.h:325
zypp::url
Url details namespace.
Definition UrlBase.cc:58
zypp::ManagedFile
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition ManagedFile.h:27
zyppng::operators
Definition expected.h:699
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::and_then
ResultType and_then(const expected< T, E > &exp, Function &&f)
Definition expected.h:520
provide.h
zypp::callback::SendReport
Definition Callback.h:237
zypp::callback::SendReport::connected
static bool connected()
Definition Callback.h:251
zypp::media::MediaChangeReport::WRONG
@ WRONG
Definition ZYppCallbacks.h:320
zypp::media::MediaChangeReport::INVALID
@ INVALID
Definition ZYppCallbacks.h:319
zypp::media::MediaChangeReport::Action
Action
Definition ZYppCallbacks.h:306
zypp::media::MediaChangeReport::CHANGE_URL
@ CHANGE_URL
Definition ZYppCallbacks.h:311
zypp::media::MediaChangeReport::IGNORE
@ IGNORE
Definition ZYppCallbacks.h:309
zypp::media::MediaChangeReport::ABORT
@ ABORT
Definition ZYppCallbacks.h:307
zypp::media::MediaChangeReport::EJECT
@ EJECT
Definition ZYppCallbacks.h:312
zypp::media::MediaChangeReport::RETRY
@ RETRY
Definition ZYppCallbacks.h:308
zypp::str::Str
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition String.h:213
userrequestexception.h
IMPL_PTR_TYPE
#define IMPL_PTR_TYPE(NAME)
Definition ReferenceCounted.h:137
ZYPP_IMPL_PRIVATE_CONSTR
#define ZYPP_IMPL_PRIVATE_CONSTR(Class)
Definition zyppglobal.h:215