libzypp 17.28.8
MediaManager.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <map>
13#include <list>
14#include <iostream>
15#include <typeinfo>
16
21#include <zypp/media/Mount.h>
22
23#include <zypp/base/String.h>
24#include <zypp/base/Logger.h>
25#include <zypp/Pathname.h>
26#include <zypp/PathInfo.h>
27
29namespace zypp
30{
31
33 namespace media
34 {
35
37 namespace // anonymous
38 {
39
40 struct ManagedMedia;
41 std::ostream & operator<<( std::ostream & str, const ManagedMedia & obj );
42
43 // -------------------------------------------------------------
44 struct ManagedMedia
45 {
46 ~ManagedMedia()
47 {
48 try
49 {
50 close(); // !!! make sure handler gets properly deleted.
51 }
52 catch(...) {}
53 }
54
55 ManagedMedia( ManagedMedia &&m )
56 : desired ( m.desired )
57 , verifier( std::move(m.verifier) )
58 , _handler ( std::move(m._handler) )
59 {}
60
61 static ManagedMedia makeManagedMedia ( const Url &o_url, const Pathname &preferred_attach_point, const MediaVerifierRef &v )
62 {
63 auto handler = MediaHandlerFactory::createHandler( o_url, preferred_attach_point );
64 if ( !handler ) {
65 ERR << "Failed to create media handler" << std::endl;
66 ZYPP_THROW( MediaSystemException(o_url, "Failed to create media handler"));
67 }
68 return ManagedMedia( std::move(handler), v );
69 }
70
71 ManagedMedia &operator= ( ManagedMedia &&other ) = default;
72
73 operator bool () const {
74 return ( _handler ? true : false );
75 }
76
77 inline MediaHandler &handler() {
78 if ( !_handler )
79 ZYPP_THROW(MediaNotOpenException("Accessing ManagedMedia after it was closed"));
80 return *_handler;
81 }
82
83 inline const MediaHandler &handler() const {
84 if ( !_handler )
85 ZYPP_THROW(MediaNotOpenException("Accessing ManagedMedia after it was closed"));
86 return *_handler;
87 }
88
89 std::ostream & dumpOn( std::ostream & str ) const {
90 if ( !_handler )
91 return str << "ManagedMedia( closed )";
92
93 str << _handler->protocol() << "(" << *_handler << ")";
94 return str;
95 }
96
97 inline void close ()
98 {
100 // !!! make shure handler gets properly deleted.
101 // I.e. release attached media before deleting the handler.
103
104 try {
105 handler().release();
106 }
107 catch (const MediaException & excpt_r)
108 {
109 ZYPP_CAUGHT(excpt_r);
110 WAR << "Close: " << *this << " (" << excpt_r << ")" << std::endl;
111 ZYPP_RETHROW(excpt_r);
112 }
113 MIL << "Close: " << *this << " (OK)" << std::endl;
114 }
115
116 inline void
117 checkAttached(MediaAccessId id)
118 {
119 if( !handler().isAttached())
120 {
121 DBG << "checkAttached(" << id << ") not attached" << std::endl;
122 desired = false;
123 ZYPP_THROW(MediaNotAttachedException(
124 handler().url()
125 ));
126 }
127 }
128
129 inline void checkDesired( MediaAccessId id )
130 {
131 checkAttached( id );
132
133 if ( !desired )
134 {
135 const auto &hdl = handler();
136 try {
137 desired = verifier->isDesiredMedia( handler() );
138 } catch ( const zypp::Exception &e ) {
139 ZYPP_CAUGHT( e );
140
141 media::MediaNotDesiredException newEx ( hdl.url() );
142 newEx.remember( e );
143 ZYPP_THROW( newEx );
144 }
145
146 if( !desired )
147 {
148 DBG << "checkDesired(" << id << "): not desired (report by " << verifier->info() << ")" << std::endl;
149 ZYPP_THROW( MediaNotDesiredException( hdl.url() ) );
150 }
151
152 DBG << "checkDesired(" << id << "): desired (report by " << verifier->info() << ")" << std::endl;
153 } else {
154 DBG << "checkDesired(" << id << "): desired (cached)" << std::endl;
155 }
156 }
157
160 Pathname deltafile;
161
162 private:
163 ManagedMedia( std::unique_ptr<MediaHandler> &&h, const MediaVerifierRef &v)
164 : desired (false)
165 , verifier(v)
166 , _handler ( std::move(h) )
167 {}
168
169 std::unique_ptr<MediaHandler> _handler;
170 };
171
172 std::ostream & operator<<( std::ostream & str, const ManagedMedia & obj ) {
173 return obj.dumpOn( str );
174 }
175
176 // -------------------------------------------------------------
177 typedef std::map<MediaAccessId, ManagedMedia> ManagedMediaMap;
178
180 } // anonymous
182
183
185 std::string
187 {
188 return std::string(typeid((*this)).name());
189 }
190
191
193 std::string
195 {
196 return std::string("zypp::media::NoVerifier");
197 }
198
199
202 {
203 private:
204 friend class MediaManager;
205
207 ManagedMediaMap mediaMap;
208
210 : last_accessid(0)
211 {}
212
213 public:
215 {
216 try
217 {
218 // remove depending (iso) handlers first
219 ManagedMediaMap::iterator it;
220 bool found;
221 do
222 {
223 found = false;
224 for(it = mediaMap.begin(); it != mediaMap.end(); )
225 {
226 if( it->second && it->second.handler().dependsOnParent() )
227 {
228 found = true;
229 // let it forget its parent, we will
230 // destroy it later (in clear())...
231 it->second.handler().resetParentId();
232 it = mediaMap.erase( it ); // postfix! Incrementing before erase
233 } else {
234 ++it;
235 }
236 }
237 } while(found);
238
239 // remove all other handlers
240 mediaMap.clear();
241 }
242 catch( ... )
243 {}
244 }
245
246 inline MediaAccessId
248 {
249 return ++last_accessid;
250 }
251
252 inline bool
253 hasId(MediaAccessId accessId) const
254 {
255 return mediaMap.find(accessId) != mediaMap.end();
256 }
257
258 inline ManagedMedia &
260 {
261 ManagedMediaMap::iterator it( mediaMap.find(accessId));
262 if( it == mediaMap.end())
263 {
265 "Invalid media access id " + str::numstring(accessId)
266 ));
267 }
268 return it->second;
269 }
270
271 static inline time_t
273 {
274 time_t mtime = zypp::PathInfo("/etc/mtab").mtime();
275 if( mtime <= 0)
276 {
277 WAR << "Failed to retrieve modification time of '/etc/mtab'"
278 << std::endl;
279 }
280 return mtime;
281 }
282
283 static inline MountEntries
285 {
286 return Mount::getEntries();
287 }
288
289 };
290
291
293 // STATIC
295
296
299 {
300 if( !m_impl)
301 {
302 m_impl.reset( new MediaManager_Impl());
303 }
304 }
305
306 // ---------------------------------------------------------------
308 {
309 }
310
311 // ---------------------------------------------------------------
313 MediaManager::open(const Url &url, const Pathname &preferred_attach_point)
314 {
315 // create new access handler for it
317 ManagedMedia tmp = ManagedMedia::makeManagedMedia( url, preferred_attach_point, verifier );
318
319 MediaAccessId nextId = m_impl->nextAccessId();
320
321 m_impl->mediaMap.insert( std::make_pair( nextId, std::move(tmp) ) );
322 //m_impl->mediaMap[nextId] = std::move(tmp);
323
324 DBG << "Opened new media access using id " << nextId
325 << " to " << url.asString() << std::endl;
326 return nextId;
327 }
328
329 // ---------------------------------------------------------------
330 void
332 {
333 //
334 // The MediaISO handler internally requests an accessId
335 // of a "parent" handler providing the iso file.
336 // The parent handler accessId is private to MediaISO,
337 // but the attached media source may be shared reference.
338 // This means, that if the accessId exactly matches the
339 // parent handler id, close was used on uninitialized
340 // accessId variable (or the accessId was guessed) and
341 // the close request to this id will be rejected here.
342 //
343 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
344 for( ; m != m_impl->mediaMap.end(); ++m)
345 {
346 if( m->second.handler().dependsOnParent(accessId, true))
347 {
349 m->second.handler().url().asString()
350 ));
351 }
352 }
353
354 DBG << "Close to access handler using id "
355 << accessId << " requested" << std::endl;
356
357 ManagedMedia &ref( m_impl->findMM(accessId));
358 ref.close();
359
360 m_impl->mediaMap.erase(accessId);
361 }
362
363 // ---------------------------------------------------------------
364 bool
366 {
367 ManagedMediaMap::iterator it( m_impl->mediaMap.find(accessId));
368 return it != m_impl->mediaMap.end();
369 }
370
371 // ---------------------------------------------------------------
372 std::string
374 {
375 ManagedMedia &ref( m_impl->findMM(accessId));
376
377 return ref.handler().protocol();
378 }
379
380 // ---------------------------------------------------------------
381 bool
383 {
384 ManagedMedia &ref( m_impl->findMM(accessId));
385
386 return ref.handler().downloads();
387 }
388
389 // ---------------------------------------------------------------
390 Url
392 {
393 ManagedMedia &ref( m_impl->findMM(accessId));
394
395 return ref.handler().url();
396 }
397
398 // ---------------------------------------------------------------
399 void
402 {
403 if( !verifier)
404 ZYPP_THROW(MediaException("Invalid verifier reference"));
405
406 ManagedMedia &ref( m_impl->findMM(accessId));
407
408 ref.desired = false;
409 MediaVerifierRef(verifier).swap(ref.verifier);
410
411 DBG << "MediaVerifier change: id=" << accessId << ", verifier="
412 << verifier->info() << std::endl;
413 }
414
415 // ---------------------------------------------------------------
416 void
418 {
419 ManagedMedia &ref( m_impl->findMM(accessId));
420
422 ref.desired = false;
423 ref.verifier.swap(verifier);
424
425 DBG << "MediaVerifier change: id=" << accessId << ", verifier="
426 << verifier->info() << std::endl;
427 }
428
429 // ---------------------------------------------------------------
430 bool
432 {
433 return MediaHandler::setAttachPrefix(attach_prefix);
434 }
435
436 // ---------------------------------------------------------------
438 {
439 ManagedMedia &ref( m_impl->findMM(accessId));
440 auto &hdl = ref.handler();
441
442 DBG << "attach(id=" << accessId << ")" << std::endl;
443
444 // try first mountable/mounted device
445 hdl.attach(false);
446 try
447 {
448 ref.checkDesired(accessId);
449 return;
450 }
451 catch (const MediaException & ex)
452 {
453 ZYPP_CAUGHT(ex);
454
455 if (!hdl.hasMoreDevices())
456 ZYPP_RETHROW(ex);
457
458 if (hdl.isAttached())
459 hdl.release();
460 }
461
462 MIL << "checkDesired(" << accessId << ") of first device failed,"
463 " going to try others with attach(true)" << std::endl;
464
465 while (hdl.hasMoreDevices())
466 {
467 try
468 {
469 // try to attach next device
470 hdl.attach(true);
471 ref.checkDesired(accessId);
472 return;
473 }
474 catch (const MediaNotDesiredException & ex)
475 {
476 ZYPP_CAUGHT(ex);
477
478 if (!hdl.hasMoreDevices())
479 {
480 MIL << "No desired media found after trying all detected devices." << std::endl;
481 ZYPP_RETHROW(ex);
482 }
483
484 AttachedMedia media(hdl.attachedMedia());
485 DBG << "Skipping " << media.mediaSource->asString() << ": not desired media." << std::endl;
486
487 hdl.release();
488 }
489 catch (const MediaException & ex)
490 {
491 ZYPP_CAUGHT(ex);
492
493 if (!hdl.hasMoreDevices())
494 ZYPP_RETHROW(ex);
495
496 AttachedMedia media(hdl.attachedMedia());
497 DBG << "Skipping " << media.mediaSource->asString() << " because of exception thrown by attach(true)" << std::endl;
498
499 if (hdl.isAttached()) hdl.release();
500 }
501 }
502 }
503
504 // ---------------------------------------------------------------
505 void
506 MediaManager::release(MediaAccessId accessId, const std::string & ejectDev)
507 {
508 ManagedMedia &ref( m_impl->findMM(accessId));
509
510 DBG << "release(id=" << accessId;
511 if (!ejectDev.empty())
512 DBG << ", " << ejectDev;
513 DBG << ")" << std::endl;
514
515 if(!ejectDev.empty())
516 {
517 //
518 // release MediaISO handlers, that are using the one
519 // specified with accessId, because it provides the
520 // iso file and it will disappear now (forced release
521 // with eject).
522 //
523 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
524 for( ; m != m_impl->mediaMap.end(); ++m)
525 {
526 auto &hdl = m->second.handler();
527 if( hdl.dependsOnParent(accessId, false))
528 {
529 try
530 {
531 DBG << "Forcing release of handler depending on access id "
532 << accessId << std::endl;
533 m->second.desired = false;
534 hdl.release();
535 }
536 catch(const MediaException &e)
537 {
538 ZYPP_CAUGHT(e);
539 }
540 }
541 }
542 }
543 ref.desired = false;
544 ref.handler().release(ejectDev);
545 }
546
547 // ---------------------------------------------------------------
548 void
550 {
551 MIL << "Releasing all attached media" << std::endl;
552
553 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
554 for( ; m != m_impl->mediaMap.end(); ++m)
555 {
556 auto &hdl = m->second.handler();
557 if( hdl.dependsOnParent())
558 continue;
559
560 try
561 {
562 if(hdl.isAttached())
563 {
564 DBG << "Releasing media id " << m->first << std::endl;
565 m->second.desired = false;
566 hdl.release();
567 }
568 else
569 {
570 DBG << "Media id " << m->first << " not attached " << std::endl;
571 }
572 }
573 catch(const MediaException & e)
574 {
575 ZYPP_CAUGHT(e);
576 ERR << "Failed to release media id " << m->first << std::endl;
577 }
578 }
579
580 MIL << "Exit" << std::endl;
581 }
582
583 // ---------------------------------------------------------------
584 void
586 {
587 ManagedMedia &ref( m_impl->findMM(accessId));
588
589 ref.handler().disconnect();
590 }
591
592 // ---------------------------------------------------------------
593 bool
595 {
596 ManagedMedia &ref( m_impl->findMM(accessId));
597
598 return ref.handler().isAttached();
599 }
600
601 // ---------------------------------------------------------------
603 {
604 ManagedMedia &ref( m_impl->findMM(accessId));
605
606 return ref.handler().isSharedMedia();
607 }
608
609 // ---------------------------------------------------------------
610 bool
612 {
613 ManagedMedia &ref( m_impl->findMM(accessId));
614
615 if( !ref.handler().isAttached())
616 {
617 ref.desired = false;
618 }
619 else
620 {
621 try {
622 ref.desired = ref.verifier->isDesiredMedia( ref.handler() );
623 }
624 catch(const zypp::Exception &e) {
625 ZYPP_CAUGHT(e);
626 ref.desired = false;
627 }
628 }
629 DBG << "isDesiredMedia(" << accessId << "): "
630 << (ref.desired ? "" : "not ")
631 << "desired (report by "
632 << ref.verifier->info() << ")" << std::endl;
633 return ref.desired;
634 }
635
636 // ---------------------------------------------------------------
637 bool
639 const MediaVerifierRef &verifier) const
640 {
642 if( !v)
643 ZYPP_THROW(MediaException("Invalid verifier reference"));
644
645 ManagedMedia &ref( m_impl->findMM(accessId));
646
647 bool desired = false;
648 if( ref.handler().isAttached())
649 {
650 try {
651 desired = v->isDesiredMedia( ref.handler() );
652 }
653 catch(const zypp::Exception &e) {
654 ZYPP_CAUGHT(e);
655 desired = false;
656 }
657 }
658 DBG << "isDesiredMedia(" << accessId << "): "
659 << (desired ? "" : "not ")
660 << "desired (report by "
661 << v->info() << ")" << std::endl;
662 return desired;
663 }
664
665 // ---------------------------------------------------------------
666 bool
668 {
669 return url(accessId).getScheme() == "cd" || url(accessId).getScheme() == "dvd";
670 }
671
672 // ---------------------------------------------------------------
675 {
676 ManagedMedia &ref( m_impl->findMM(accessId));
677
678 Pathname path;
679 path = ref.handler().localRoot();
680 return path;
681 }
682
683 // ---------------------------------------------------------------
686 const Pathname & pathname) const
687 {
688 ManagedMedia &ref( m_impl->findMM(accessId));
689
690 Pathname path;
691 path = ref.handler().localPath(pathname);
692 return path;
693 }
694
695 void
697 const Pathname &filename,
698 const ByteCount &expectedFileSize ) const
699 {
700 ManagedMedia &ref( m_impl->findMM(accessId));
701
702 auto loc = OnMediaLocation( filename )
703 .setDownloadSize( expectedFileSize )
704 .setDeltafile( ref.deltafile );
705
706 provideFile( accessId, loc );
707 }
708
709 // ---------------------------------------------------------------
710 void
712 const Pathname &filename ) const
713 {
714 ManagedMedia &ref( m_impl->findMM(accessId));
715
716 auto loc = OnMediaLocation( filename )
717 .setDeltafile( ref.deltafile );
718
719 provideFile( accessId, loc );
720 }
721
722 void MediaManager::provideFile( MediaAccessId accessId, const OnMediaLocation &file ) const
723 {
724 ManagedMedia &ref( m_impl->findMM(accessId));
725
726 ref.checkDesired(accessId);
727
728 ref.handler().provideFile( file );
729 }
730
731 // ---------------------------------------------------------------
732 void
734 const Pathname &filename ) const
735 {
736 ManagedMedia &ref( m_impl->findMM(accessId));
737
738 ref.checkDesired(accessId);
739
740 ref.deltafile = filename;
741 }
742
743 void MediaManager::precacheFiles(MediaAccessId accessId, const std::vector<OnMediaLocation> &files)
744 {
745 ManagedMedia &ref( m_impl->findMM(accessId));
746
747 ref.checkDesired(accessId);
748
749 ref.handler().precacheFiles( files );
750 }
751
752 // ---------------------------------------------------------------
753 void
755 const Pathname &dirname) const
756 {
757 ManagedMedia &ref( m_impl->findMM(accessId));
758
759 ref.checkDesired(accessId);
760
761 ref.handler().provideDir(dirname);
762 }
763
764 // ---------------------------------------------------------------
765 void
767 const Pathname &dirname) const
768 {
769 ManagedMedia &ref( m_impl->findMM(accessId));
770
771 ref.checkDesired(accessId);
772
773 ref.handler().provideDirTree(dirname);
774 }
775
776 // ---------------------------------------------------------------
777 void
779 const Pathname &filename) const
780 {
781 ManagedMedia &ref( m_impl->findMM(accessId));
782
783 ref.checkAttached(accessId);
784
785 ref.handler().releaseFile(filename);
786 }
787
788 // ---------------------------------------------------------------
789 void
791 const Pathname &dirname) const
792 {
793 ManagedMedia &ref( m_impl->findMM(accessId));
794
795 ref.checkAttached(accessId);
796
797 ref.handler().releaseDir(dirname);
798 }
799
800
801 // ---------------------------------------------------------------
802 void
804 const Pathname &pathname) const
805 {
806 ManagedMedia &ref( m_impl->findMM(accessId));
807
808 ref.checkAttached(accessId);
809
810 ref.handler().releasePath(pathname);
811 }
812
813 // ---------------------------------------------------------------
814 void
816 std::list<std::string> &retlist,
817 const Pathname &dirname,
818 bool dots) const
819 {
820 ManagedMedia &ref( m_impl->findMM(accessId));
821
822 // FIXME: ref.checkDesired(accessId); ???
823 ref.checkAttached(accessId);
824
825 ref.handler().dirInfo(retlist, dirname, dots);
826 }
827
828 // ---------------------------------------------------------------
829 void
831 filesystem::DirContent &retlist,
832 const Pathname &dirname,
833 bool dots) const
834 {
835 ManagedMedia &ref( m_impl->findMM(accessId));
836
837 // FIXME: ref.checkDesired(accessId); ???
838 ref.checkAttached(accessId);
839
840 ref.handler().dirInfo(retlist, dirname, dots);
841 }
842
843 // ---------------------------------------------------------------
844 bool
845 MediaManager::doesFileExist(MediaAccessId accessId, const Pathname & filename ) const
846 {
847 ManagedMedia &ref( m_impl->findMM(accessId));
848
849 // FIXME: ref.checkDesired(accessId); ???
850 ref.checkAttached(accessId);
851
852 return ref.handler().doesFileExist(filename);
853 }
854
855 // ---------------------------------------------------------------
856 void
858 std::vector<std::string> & devices,
859 unsigned int & index) const
860 {
861 ManagedMedia &ref( m_impl->findMM(accessId));
862 return ref.handler().getDetectedDevices(devices, index);
863 }
864
865 // ---------------------------------------------------------------
866 // STATIC
867 time_t
869 {
871 }
872
873 // ---------------------------------------------------------------
874 // STATIC
875 MountEntries
877 {
879 }
880
881 // ---------------------------------------------------------------
882 bool
884 bool mtab) const
885 {
886 if( path.empty() || path == "/" || !PathInfo(path).isDir())
887 return false;
888
889 //
890 // check against our current attach points
891 //
892 ManagedMediaMap::const_iterator m(m_impl->mediaMap.begin());
893 for( ; m != m_impl->mediaMap.end(); ++m)
894 {
895 AttachedMedia ret = m->second.handler().attachedMedia();
896 if( ret.mediaSource && ret.attachPoint)
897 {
898 std::string mnt(ret.attachPoint->path.asString());
899 std::string our(path.asString());
900
901 if( our == mnt)
902 {
903 // already used as attach point
904 return false;
905 }
906 else
907 if( mnt.size() > our.size() &&
908 mnt.at(our.size()) == '/' &&
909 !mnt.compare(0, our.size(), our))
910 {
911 // mountpoint is bellow of path
912 // (would hide the content)
913 return false;
914 }
915 }
916 }
917
918 if( !mtab)
919 return true;
920
921 //
922 // check against system mount entries
923 //
924 MountEntries entries( m_impl->getMountEntries());
925 MountEntries::const_iterator e;
926 for( e = entries.begin(); e != entries.end(); ++e)
927 {
928 std::string mnt(Pathname(e->dir).asString());
929 std::string our(path.asString());
930
931 if( our == mnt)
932 {
933 // already used as mountpoint
934 return false;
935 }
936 else
937 if( mnt.size() > our.size() &&
938 mnt.at(our.size()) == '/' &&
939 !mnt.compare(0, our.size(), our))
940 {
941 // mountpoint is bellow of path
942 // (would hide the content)
943 return false;
944 }
945 }
946
947 return true;
948 }
949
950 // ---------------------------------------------------------------
953 {
954 ManagedMedia &ref( m_impl->findMM(accessId));
955
956 return ref.handler().attachedMedia();
957 }
958
959 // ---------------------------------------------------------------
962 {
963 if( !media || media->type.empty())
964 return AttachedMedia();
965
966 ManagedMediaMap::const_iterator m(m_impl->mediaMap.begin());
967 for( ; m != m_impl->mediaMap.end(); ++m)
968 {
969 if( !m->second.handler().isAttached())
970 continue;
971
972 AttachedMedia ret = m->second.handler().attachedMedia();
973 if( ret.mediaSource && ret.mediaSource->equals( *media))
974 return ret;
975 }
976 return AttachedMedia();
977 }
978
979 // ---------------------------------------------------------------
980 void
982 {
983 if( !media || media->type.empty())
984 return;
985
986 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
987 for( ; m != m_impl->mediaMap.end(); ++m)
988 {
989 if( !m->second.handler().isAttached())
990 continue;
991
992 AttachedMedia ret = m->second.handler().attachedMedia();
993 if( ret.mediaSource && ret.mediaSource->equals( *media))
994 {
995 m->second.handler().release();
996 m->second.desired = false;
997 }
998 }
999 }
1000
1002 } // namespace media
1004
1006} // namespace zypp
1008/*
1009** vim: set ts=2 sts=2 sw=2 ai et:
1010*/
std::unique_ptr< MediaHandler > _handler
MediaVerifierRef verifier
Pathname deltafile
bool desired
Store and operate with byte count.
Definition: ByteCount.h:31
Base class for Exception.
Definition: Exception.h:146
Describes a resource file located on a medium.
OnMediaLocation & setDownloadSize(ByteCount val_r)
Set the downloadSize.
OnMediaLocation & setDeltafile(Pathname path)
Set the deltafile.
Url manipulation class.
Definition: Url.h:92
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:533
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:497
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:221
time_t mtime() const
Definition: PathInfo.h:376
const std::string & asString() const
String representation.
Definition: Pathname.h:91
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
Just inherits Exception to separate media exceptions.
static std::unique_ptr< MediaHandler > createHandler(const Url &o_url, const Pathname &preferred_attach_point)
static bool setAttachPrefix(const Pathname &attach_prefix)
static MountEntries getMountEntries()
bool hasId(MediaAccessId accessId) const
ManagedMedia & findMM(MediaAccessId accessId)
static time_t getMountTableMTime()
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees,...
Definition: MediaManager.h:454
ZYPP_DEPRECATED void setDeltafile(MediaAccessId accessId, const Pathname &filename) const
MediaAccessId open(const Url &url, const Pathname &preferred_attach_point="")
Opens the media access for specified with the url.
void delVerifier(MediaAccessId accessId)
Remove verifier for specified media id.
void releaseFile(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
bool isChangeable(MediaAccessId accessId)
Simple check, based on media's URL scheme, telling whether the it is possible to physically change th...
void forceReleaseShared(const MediaSourceRef &media)
void releaseAll()
Release all attached media.
static zypp::RW_pointer< MediaManager_Impl > m_impl
Static reference to the implementation (singleton).
Definition: MediaManager.h:925
void disconnect(MediaAccessId accessId)
Disconnect a remote media.
void attach(MediaAccessId accessId)
Attach the media using the concrete handler (checks all devices).
void releaseDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
bool isOpen(MediaAccessId accessId) const
Query if the media access is open / exists.
void releasePath(MediaAccessId accessId, const Pathname &pathname) const
FIXME: see MediaAccess class.
void dirInfo(MediaAccessId accessId, std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
FIXME: see MediaAccess class.
void close(MediaAccessId accessId)
Close the media access with specified id.
Url url(MediaAccessId accessId) const
Returns the Media Access Url of the media access id.
bool isDesiredMedia(MediaAccessId accessId) const
Ask the registered verifier if the attached media is the desired one or not.
ZYPP_DEPRECATED void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
void precacheFiles(MediaAccessId accessId, const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
bool isAttached(MediaAccessId accessId) const
Check if media is attached or not.
AttachedMedia getAttachedMedia(MediaAccessId &accessId) const
static time_t getMountTableMTime()
Get the modification time of the /etc/mtab file.
~MediaManager()
Destroys MediaManager envelope instance.
bool isSharedMedia(MediaAccessId accessId) const
Returns information if media is on a shared physical device or not.
std::string protocol(MediaAccessId accessId) const
Query the protocol name used by the media access handler.
bool doesFileExist(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
void provideDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Check if the specified path is useable as attach point.
MediaManager()
Creates a MediaManager envelope instance.
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for 'localRoot() + pathname', but returns an empty pathname if media is not attached.
void provideDirTree(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
void addVerifier(MediaAccessId accessId, const MediaVerifierRef &verifier)
Add verifier implementation for the specified media id.
bool setAttachPrefix(const Pathname &attach_prefix)
Set or resets the directory name, where the media manager handlers create their temporary attach poin...
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 ...
Pathname localRoot(MediaAccessId accessId) const
Return the local directory that corresponds to medias url, no matter if media isAttached or not.
bool downloads(MediaAccessId accessId) const
Hint if files are downloaded or not.
static std::vector< MountEntry > getMountEntries()
Get current mount entries from /etc/mtab file.
virtual std::string info() const
Returns a string with some info about the verifier.
static MountEntries getEntries(const std::string &mtab="")
Return mount entries from /etc/mtab or /etc/fstab file.
Definition: Mount.cc:276
Dummy default media verifier, which is always happy.
Definition: MediaManager.h:78
std::string info() const override
Returns the "zypp::media::NoVerifier" string.
Definition: Hash.h:38
String related utilities and Regular expression matching.
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:518
zypp::RW_pointer< MediaVerifierBase > MediaVerifierRef
A shared reference to the MediaVerifier implementation.
Definition: MediaManager.h:107
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
std::ostream & operator<<(std::ostream &str, const MediaBlockList &bl)
std::string numstring(char n, int w=0)
Definition: String.h:289
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:444
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:286
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:134
MediaSourceRef mediaSource
Definition: MediaSource.h:144
AttachPointRef attachPoint
Definition: MediaSource.h:145
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:400
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:396
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
#define DBG
Definition: Logger.h:95
#define MIL
Definition: Logger.h:96
#define ERR
Definition: Logger.h:98
#define WAR
Definition: Logger.h:97