libzypp 17.31.23
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
17#include <zypp-media/MediaException>
21#include <zypp-media/Mount>
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 if ( _handler )
51 close(); // !!! make sure handler gets properly deleted.
52 }
53 catch(...) {}
54 }
55
56 ManagedMedia( ManagedMedia &&m )
57 : desired ( m.desired )
58 , verifier( std::move(m.verifier) )
59 , _handler ( std::move(m._handler) )
60 {}
61
62 static ManagedMedia makeManagedMedia ( const Url &o_url, const Pathname &preferred_attach_point, const MediaVerifierRef &v )
63 {
64 auto handler = MediaHandlerFactory::createHandler( o_url, preferred_attach_point );
65 if ( !handler ) {
66 ERR << "Failed to create media handler" << std::endl;
67 ZYPP_THROW( MediaSystemException(o_url, "Failed to create media handler"));
68 }
69 return ManagedMedia( std::move(handler), v );
70 }
71
72 ManagedMedia &operator= ( ManagedMedia &&other ) = default;
73
74 operator bool () const {
75 return ( _handler ? true : false );
76 }
77
78 inline MediaHandler &handler() {
79 if ( !_handler )
80 ZYPP_THROW(MediaNotOpenException("Accessing ManagedMedia after it was closed"));
81 return *_handler;
82 }
83
84 inline const MediaHandler &handler() const {
85 if ( !_handler )
86 ZYPP_THROW(MediaNotOpenException("Accessing ManagedMedia after it was closed"));
87 return *_handler;
88 }
89
90 std::ostream & dumpOn( std::ostream & str ) const {
91 if ( !_handler )
92 return str << "ManagedMedia( closed )";
93
94 str << _handler->protocol() << "(" << *_handler << ")";
95 return str;
96 }
97
98 inline void close ()
99 {
101 // !!! make shure handler gets properly deleted.
102 // I.e. release attached media before deleting the handler.
104
105 try {
106 handler().release();
107 }
108 catch (const MediaException & excpt_r)
109 {
110 ZYPP_CAUGHT(excpt_r);
111 WAR << "Close: " << *this << " (" << excpt_r << ")" << std::endl;
112 ZYPP_RETHROW(excpt_r);
113 }
114 MIL << "Close: " << *this << " (OK)" << std::endl;
115 }
116
117 inline void
118 checkAttached(MediaAccessId id)
119 {
120 if( !handler().isAttached())
121 {
122 DBG << "checkAttached(" << id << ") not attached" << std::endl;
123 desired = false;
124 ZYPP_THROW(MediaNotAttachedException(
125 handler().url()
126 ));
127 }
128 }
129
130 inline void checkDesired( MediaAccessId id )
131 {
132 checkAttached( id );
133
134 if ( !desired )
135 {
136 const auto &hdl = handler();
137 try {
138 desired = verifier->isDesiredMedia( handler() );
139 } catch ( const zypp::Exception &e ) {
140 ZYPP_CAUGHT( e );
141
142 media::MediaNotDesiredException newEx ( hdl.url() );
143 newEx.remember( e );
144 ZYPP_THROW( newEx );
145 }
146
147 if( !desired )
148 {
149 DBG << "checkDesired(" << id << "): not desired (report by " << verifier->info() << ")" << std::endl;
150 ZYPP_THROW( MediaNotDesiredException( hdl.url() ) );
151 }
152
153 DBG << "checkDesired(" << id << "): desired (report by " << verifier->info() << ")" << std::endl;
154 } else {
155 DBG << "checkDesired(" << id << "): desired (cached)" << std::endl;
156 }
157 }
158
161 Pathname deltafile;
162
163 private:
164 ManagedMedia( std::unique_ptr<MediaHandler> &&h, const MediaVerifierRef &v)
165 : desired (false)
166 , verifier(v)
167 , _handler ( std::move(h) )
168 {}
169
170 std::unique_ptr<MediaHandler> _handler;
171 };
172
173 std::ostream & operator<<( std::ostream & str, const ManagedMedia & obj ) {
174 return obj.dumpOn( str );
175 }
176
177 // -------------------------------------------------------------
178 typedef std::map<MediaAccessId, ManagedMedia> ManagedMediaMap;
179
181 } // anonymous
183
184
186 std::string
188 {
189 return std::string(typeid((*this)).name());
190 }
191
192
194 std::string
196 {
197 return std::string("zypp::media::NoVerifier");
198 }
199
200
203 {
204 private:
205 friend class MediaManager;
206
208 ManagedMediaMap mediaMap;
209
211 : last_accessid(0)
212 {}
213
214 public:
216 {
217 try
218 {
219 // remove depending (iso) handlers first
220 ManagedMediaMap::iterator it;
221 bool found;
222 do
223 {
224 found = false;
225 for(it = mediaMap.begin(); it != mediaMap.end(); )
226 {
227 if( it->second && it->second.handler().dependsOnParent() )
228 {
229 found = true;
230 // let it forget its parent, we will
231 // destroy it later (in clear())...
232 it->second.handler().resetParentId();
233 it = mediaMap.erase( it ); // postfix! Incrementing before erase
234 } else {
235 ++it;
236 }
237 }
238 } while(found);
239
240 // remove all other handlers
241 mediaMap.clear();
242 }
243 catch( ... )
244 {}
245 }
246
247 inline MediaAccessId
249 {
250 return ++last_accessid;
251 }
252
253 inline bool
254 hasId(MediaAccessId accessId) const
255 {
256 return mediaMap.find(accessId) != mediaMap.end();
257 }
258
259 inline ManagedMedia &
261 {
262 ManagedMediaMap::iterator it( mediaMap.find(accessId));
263 if( it == mediaMap.end())
264 {
266 "Invalid media access id " + str::numstring(accessId)
267 ));
268 }
269 return it->second;
270 }
271
272 static inline time_t
274 {
275 return Mount::getMTime();
276 }
277
278 static inline MountEntries
280 {
281 return Mount::getEntries();
282 }
283
284 };
285
286
288 // STATIC
290
291
294 {
295 if( !m_impl)
296 {
297 m_impl.reset( new MediaManager_Impl());
298 }
299 }
300
301 // ---------------------------------------------------------------
303 {
304 }
305
306 // ---------------------------------------------------------------
308 MediaManager::open(const Url &url, const Pathname &preferred_attach_point)
309 {
310 // create new access handler for it
312 ManagedMedia tmp = ManagedMedia::makeManagedMedia( url, preferred_attach_point, verifier );
313
314 MediaAccessId nextId = m_impl->nextAccessId();
315
316 m_impl->mediaMap.insert( std::make_pair( nextId, std::move(tmp) ) );
317 //m_impl->mediaMap[nextId] = std::move(tmp);
318
319 DBG << "Opened new media access using id " << nextId
320 << " to " << url.asString() << std::endl;
321 return nextId;
322 }
323
324 // ---------------------------------------------------------------
325 void
327 {
328 //
329 // The MediaISO handler internally requests an accessId
330 // of a "parent" handler providing the iso file.
331 // The parent handler accessId is private to MediaISO,
332 // but the attached media source may be shared reference.
333 // This means, that if the accessId exactly matches the
334 // parent handler id, close was used on uninitialized
335 // accessId variable (or the accessId was guessed) and
336 // the close request to this id will be rejected here.
337 //
338 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
339 for( ; m != m_impl->mediaMap.end(); ++m)
340 {
341 if( m->second.handler().dependsOnParent(accessId, true))
342 {
344 m->second.handler().url().asString()
345 ));
346 }
347 }
348
349 DBG << "Close to access handler using id "
350 << accessId << " requested" << std::endl;
351
352 ManagedMedia &ref( m_impl->findMM(accessId));
353 ref.close();
354
355 m_impl->mediaMap.erase(accessId);
356 }
357
358 // ---------------------------------------------------------------
359 bool
361 {
362 ManagedMediaMap::iterator it( m_impl->mediaMap.find(accessId));
363 return it != m_impl->mediaMap.end();
364 }
365
366 // ---------------------------------------------------------------
367 std::string
369 {
370 ManagedMedia &ref( m_impl->findMM(accessId));
371
372 return ref.handler().protocol();
373 }
374
375 // ---------------------------------------------------------------
376 bool
378 {
379 ManagedMedia &ref( m_impl->findMM(accessId));
380
381 return ref.handler().downloads();
382 }
383
384 // ---------------------------------------------------------------
385 Url
387 {
388 ManagedMedia &ref( m_impl->findMM(accessId));
389
390 return ref.handler().url();
391 }
392
393 // ---------------------------------------------------------------
394 void
397 {
398 if( !verifier)
399 ZYPP_THROW(MediaException("Invalid verifier reference"));
400
401 ManagedMedia &ref( m_impl->findMM(accessId));
402
403 ref.desired = false;
404 MediaVerifierRef(verifier).swap(ref.verifier);
405
406 DBG << "MediaVerifier change: id=" << accessId << ", verifier="
407 << verifier->info() << std::endl;
408 }
409
410 // ---------------------------------------------------------------
411 void
413 {
414 ManagedMedia &ref( m_impl->findMM(accessId));
415
417 ref.desired = false;
418 ref.verifier.swap(verifier);
419
420 DBG << "MediaVerifier change: id=" << accessId << ", verifier="
421 << verifier->info() << std::endl;
422 }
423
424 // ---------------------------------------------------------------
425 bool
427 {
428 return MediaHandler::setAttachPrefix(attach_prefix);
429 }
430
431 // ---------------------------------------------------------------
433 {
434 ManagedMedia &ref( m_impl->findMM(accessId));
435 auto &hdl = ref.handler();
436
437 DBG << "attach(id=" << accessId << ")" << std::endl;
438
439 // try first mountable/mounted device
440 hdl.attach(false);
441 try
442 {
443 ref.checkDesired(accessId);
444 return;
445 }
446 catch (const MediaException & ex)
447 {
448 ZYPP_CAUGHT(ex);
449
450 if (!hdl.hasMoreDevices())
451 ZYPP_RETHROW(ex);
452
453 if (hdl.isAttached())
454 hdl.release();
455 }
456
457 MIL << "checkDesired(" << accessId << ") of first device failed,"
458 " going to try others with attach(true)" << std::endl;
459
460 while (hdl.hasMoreDevices())
461 {
462 try
463 {
464 // try to attach next device
465 hdl.attach(true);
466 ref.checkDesired(accessId);
467 return;
468 }
469 catch (const MediaNotDesiredException & ex)
470 {
471 ZYPP_CAUGHT(ex);
472
473 if (!hdl.hasMoreDevices())
474 {
475 MIL << "No desired media found after trying all detected devices." << std::endl;
476 ZYPP_RETHROW(ex);
477 }
478
479 AttachedMedia media(hdl.attachedMedia());
480 DBG << "Skipping " << media.mediaSource->asString() << ": not desired media." << std::endl;
481
482 hdl.release();
483 }
484 catch (const MediaException & ex)
485 {
486 ZYPP_CAUGHT(ex);
487
488 if (!hdl.hasMoreDevices())
489 ZYPP_RETHROW(ex);
490
491 AttachedMedia media(hdl.attachedMedia());
492 DBG << "Skipping " << media.mediaSource->asString() << " because of exception thrown by attach(true)" << std::endl;
493
494 if (hdl.isAttached()) hdl.release();
495 }
496 }
497 }
498
499 // ---------------------------------------------------------------
500 void
501 MediaManager::release(MediaAccessId accessId, const std::string & ejectDev)
502 {
503 ManagedMedia &ref( m_impl->findMM(accessId));
504
505 DBG << "release(id=" << accessId;
506 if (!ejectDev.empty())
507 DBG << ", " << ejectDev;
508 DBG << ")" << std::endl;
509
510 if(!ejectDev.empty())
511 {
512 //
513 // release MediaISO handlers, that are using the one
514 // specified with accessId, because it provides the
515 // iso file and it will disappear now (forced release
516 // with eject).
517 //
518 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
519 for( ; m != m_impl->mediaMap.end(); ++m)
520 {
521 auto &hdl = m->second.handler();
522 if( hdl.dependsOnParent(accessId, false))
523 {
524 try
525 {
526 DBG << "Forcing release of handler depending on access id "
527 << accessId << std::endl;
528 m->second.desired = false;
529 hdl.release();
530 }
531 catch(const MediaException &e)
532 {
533 ZYPP_CAUGHT(e);
534 }
535 }
536 }
537 }
538 ref.desired = false;
539 ref.handler().release(ejectDev);
540 }
541
542 // ---------------------------------------------------------------
543 void
545 {
546 MIL << "Releasing all attached media" << std::endl;
547 auto releaseAction = []( MediaAccessId mId_r, ManagedMedia & mManagedMedia_r, bool ifDependsOnParent_r ) {
548 auto & hdl = mManagedMedia_r.handler();
549 if ( hdl.dependsOnParent() == ifDependsOnParent_r ) {
550 try {
551 if ( hdl.isAttached() ) {
552 DBG << "Releasing media id " << mId_r << std::endl;
553 mManagedMedia_r.desired = false;
554 hdl.release();
555 }
556 else {
557 DBG << "Media id " << mId_r << " not attached " << std::endl;
558 }
559 }
560 catch ( const MediaException & e ) {
561 ZYPP_CAUGHT(e);
562 ERR << "Failed to release media id " << mId_r << std::endl;
563 }
564 }
565 };
566
567 // 1st pass releases any stacked mounts (ISO)
568 for ( auto & [ mId, mManagedMedia ] : m_impl->mediaMap ) {
569 releaseAction( mId, mManagedMedia, /*ifDependsOnParent*/true );
570 }
571 // 2nd pass releases all the rest
572 for ( auto & [ mId, mManagedMedia ] : m_impl->mediaMap ) {
573 releaseAction( mId, mManagedMedia, /*ifDependsOnParent*/false );
574 }
575
576 MIL << "Exit" << std::endl;
577 }
578
579 // ---------------------------------------------------------------
580 void
582 {
583 ManagedMedia &ref( m_impl->findMM(accessId));
584
585 ref.handler().disconnect();
586 }
587
588 // ---------------------------------------------------------------
589 bool
591 {
592 ManagedMedia &ref( m_impl->findMM(accessId));
593
594 return ref.handler().isAttached();
595 }
596
597 // ---------------------------------------------------------------
599 {
600 ManagedMedia &ref( m_impl->findMM(accessId));
601
602 return ref.handler().isSharedMedia();
603 }
604
605 // ---------------------------------------------------------------
606 bool
608 {
609 ManagedMedia &ref( m_impl->findMM(accessId));
610
611 if( !ref.handler().isAttached())
612 {
613 ref.desired = false;
614 }
615 else
616 {
617 try {
618 ref.desired = ref.verifier->isDesiredMedia( ref.handler() );
619 }
620 catch(const zypp::Exception &e) {
621 ZYPP_CAUGHT(e);
622 ref.desired = false;
623 }
624 }
625 DBG << "isDesiredMedia(" << accessId << "): "
626 << (ref.desired ? "" : "not ")
627 << "desired (report by "
628 << ref.verifier->info() << ")" << std::endl;
629 return ref.desired;
630 }
631
632 // ---------------------------------------------------------------
633 bool
635 const MediaVerifierRef &verifier) const
636 {
638 if( !v)
639 ZYPP_THROW(MediaException("Invalid verifier reference"));
640
641 ManagedMedia &ref( m_impl->findMM(accessId));
642
643 bool desired = false;
644 if( ref.handler().isAttached())
645 {
646 try {
647 desired = v->isDesiredMedia( ref.handler() );
648 }
649 catch(const zypp::Exception &e) {
650 ZYPP_CAUGHT(e);
651 desired = false;
652 }
653 }
654 DBG << "isDesiredMedia(" << accessId << "): "
655 << (desired ? "" : "not ")
656 << "desired (report by "
657 << v->info() << ")" << std::endl;
658 return desired;
659 }
660
661 // ---------------------------------------------------------------
662 bool
664 {
665 return url(accessId).getScheme() == "cd" || url(accessId).getScheme() == "dvd";
666 }
667
668 // ---------------------------------------------------------------
671 {
672 ManagedMedia &ref( m_impl->findMM(accessId));
673
674 Pathname path;
675 path = ref.handler().localRoot();
676 return path;
677 }
678
679 // ---------------------------------------------------------------
682 const Pathname & pathname) const
683 {
684 ManagedMedia &ref( m_impl->findMM(accessId));
685
686 Pathname path;
687 path = ref.handler().localPath(pathname);
688 return path;
689 }
690
691 void
693 const Pathname &filename,
694 const ByteCount &expectedFileSize ) const
695 {
696 ManagedMedia &ref( m_impl->findMM(accessId));
697
698 auto loc = OnMediaLocation( filename )
699 .setDownloadSize( expectedFileSize )
700 .setDeltafile( ref.deltafile );
701
702 provideFile( accessId, loc );
703 }
704
705 // ---------------------------------------------------------------
706 void
708 const Pathname &filename ) const
709 {
710 ManagedMedia &ref( m_impl->findMM(accessId));
711
712 auto loc = OnMediaLocation( filename )
713 .setDeltafile( ref.deltafile );
714
715 provideFile( accessId, loc );
716 }
717
718 void MediaManager::provideFile( MediaAccessId accessId, const OnMediaLocation &file ) const
719 {
720 ManagedMedia &ref( m_impl->findMM(accessId));
721
722 ref.checkDesired(accessId);
723
724 ref.handler().provideFile( file );
725 }
726
727 // ---------------------------------------------------------------
728 void
730 const Pathname &filename ) const
731 {
732 ManagedMedia &ref( m_impl->findMM(accessId));
733
734 ref.checkDesired(accessId);
735
736 ref.deltafile = filename;
737 }
738
739 void MediaManager::precacheFiles(MediaAccessId accessId, const std::vector<OnMediaLocation> &files)
740 {
741 ManagedMedia &ref( m_impl->findMM(accessId));
742
743 ref.checkDesired(accessId);
744
745 ref.handler().precacheFiles( files );
746 }
747
748 // ---------------------------------------------------------------
749 void
751 const Pathname &dirname) const
752 {
753 ManagedMedia &ref( m_impl->findMM(accessId));
754
755 ref.checkDesired(accessId);
756
757 ref.handler().provideDir(dirname);
758 }
759
760 // ---------------------------------------------------------------
761 void
763 const Pathname &dirname) const
764 {
765 ManagedMedia &ref( m_impl->findMM(accessId));
766
767 ref.checkDesired(accessId);
768
769 ref.handler().provideDirTree(dirname);
770 }
771
772 // ---------------------------------------------------------------
773 void
775 const Pathname &filename) const
776 {
777 ManagedMedia &ref( m_impl->findMM(accessId));
778
779 ref.checkAttached(accessId);
780
781 ref.handler().releaseFile(filename);
782 }
783
784 // ---------------------------------------------------------------
785 void
787 const Pathname &dirname) const
788 {
789 ManagedMedia &ref( m_impl->findMM(accessId));
790
791 ref.checkAttached(accessId);
792
793 ref.handler().releaseDir(dirname);
794 }
795
796
797 // ---------------------------------------------------------------
798 void
800 const Pathname &pathname) const
801 {
802 ManagedMedia &ref( m_impl->findMM(accessId));
803
804 ref.checkAttached(accessId);
805
806 ref.handler().releasePath(pathname);
807 }
808
809 // ---------------------------------------------------------------
810 void
812 std::list<std::string> &retlist,
813 const Pathname &dirname,
814 bool dots) const
815 {
816 ManagedMedia &ref( m_impl->findMM(accessId));
817
818 // FIXME: ref.checkDesired(accessId); ???
819 ref.checkAttached(accessId);
820
821 ref.handler().dirInfo(retlist, dirname, dots);
822 }
823
824 // ---------------------------------------------------------------
825 void
827 filesystem::DirContent &retlist,
828 const Pathname &dirname,
829 bool dots) const
830 {
831 ManagedMedia &ref( m_impl->findMM(accessId));
832
833 // FIXME: ref.checkDesired(accessId); ???
834 ref.checkAttached(accessId);
835
836 ref.handler().dirInfo(retlist, dirname, dots);
837 }
838
839 // ---------------------------------------------------------------
840 bool
841 MediaManager::doesFileExist(MediaAccessId accessId, const Pathname & filename ) const
842 {
843 ManagedMedia &ref( m_impl->findMM(accessId));
844
845 // FIXME: ref.checkDesired(accessId); ???
846 ref.checkAttached(accessId);
847
848 return ref.handler().doesFileExist(filename);
849 }
850
851 // ---------------------------------------------------------------
852 void
854 std::vector<std::string> & devices,
855 unsigned int & index) const
856 {
857 ManagedMedia &ref( m_impl->findMM(accessId));
858 return ref.handler().getDetectedDevices(devices, index);
859 }
860
861 // ---------------------------------------------------------------
862 // STATIC
863 time_t
865 {
867 }
868
869 // ---------------------------------------------------------------
870 // STATIC
871 MountEntries
873 {
875 }
876
877 // ---------------------------------------------------------------
878 bool
880 bool mtab) const
881 {
882 if( path.empty() || path == "/" || !PathInfo(path).isDir())
883 return false;
884
885 //
886 // check against our current attach points
887 //
888 ManagedMediaMap::const_iterator m(m_impl->mediaMap.begin());
889 for( ; m != m_impl->mediaMap.end(); ++m)
890 {
891 AttachedMedia ret = m->second.handler().attachedMedia();
892 if( ret.mediaSource && ret.attachPoint)
893 {
894 std::string mnt(ret.attachPoint->path.asString());
895 std::string our(path.asString());
896
897 if( our == mnt)
898 {
899 // already used as attach point
900 return false;
901 }
902 else
903 if( mnt.size() > our.size() &&
904 mnt.at(our.size()) == '/' &&
905 !mnt.compare(0, our.size(), our))
906 {
907 // mountpoint is bellow of path
908 // (would hide the content)
909 return false;
910 }
911 }
912 }
913
914 if( !mtab)
915 return true;
916
917 //
918 // check against system mount entries
919 //
920 MountEntries entries( m_impl->getMountEntries());
921 MountEntries::const_iterator e;
922 for( e = entries.begin(); e != entries.end(); ++e)
923 {
924 std::string mnt(Pathname(e->dir).asString());
925 std::string our(path.asString());
926
927 if( our == mnt)
928 {
929 // already used as mountpoint
930 return false;
931 }
932 else
933 if( mnt.size() > our.size() &&
934 mnt.at(our.size()) == '/' &&
935 !mnt.compare(0, our.size(), our))
936 {
937 // mountpoint is bellow of path
938 // (would hide the content)
939 return false;
940 }
941 }
942
943 return true;
944 }
945
946 // ---------------------------------------------------------------
949 {
950 ManagedMedia &ref( m_impl->findMM(accessId));
951
952 return ref.handler().attachedMedia();
953 }
954
955 // ---------------------------------------------------------------
958 {
959 if( !media || media->type.empty())
960 return AttachedMedia();
961
962 ManagedMediaMap::const_iterator m(m_impl->mediaMap.begin());
963 for( ; m != m_impl->mediaMap.end(); ++m)
964 {
965 if( !m->second.handler().isAttached())
966 continue;
967
968 AttachedMedia ret = m->second.handler().attachedMedia();
969 if( ret.mediaSource && ret.mediaSource->equals( *media))
970 return ret;
971 }
972 return AttachedMedia();
973 }
974
975 // ---------------------------------------------------------------
976 void
978 {
979 if( !media || media->type.empty())
980 return;
981
982 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
983 for( ; m != m_impl->mediaMap.end(); ++m)
984 {
985 if( !m->second.handler().isAttached())
986 continue;
987
988 AttachedMedia ret = m->second.handler().attachedMedia();
989 if( ret.mediaSource && ret.mediaSource->equals( *media))
990 {
991 m->second.handler().release();
992 m->second.desired = false;
993 }
994 }
995 }
996
998 } // namespace media
1000
1002} // namespace zypp
1004/*
1005** vim: set ts=2 sts=2 sw=2 ai et:
1006*/
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
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:169
static time_t getMTime()
Get the modification time of the /etc/mtab file.
Definition: mount.cc:264
Dummy default media verifier, which is always happy.
Definition: MediaManager.h:78
std::string info() const override
Returns the "zypp::media::NoVerifier" string.
Definition: Arch.h:361
String related utilities and Regular expression matching.
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:518
std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
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::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:580
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:440
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:436
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:428
#define DBG
Definition: Logger.h:95
#define MIL
Definition: Logger.h:96
#define ERR
Definition: Logger.h:98
#define WAR
Definition: Logger.h:97