libzypp 17.36.7

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