libzypp 17.29.1
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 {
265 ZYPP_THROW(MediaNotOpenException(
266 "Invalid media access id " + str::numstring(accessId)
267 ));
268 }
269 return it->second;
270 }
271
272 static inline time_t
274 {
275 time_t mtime = zypp::PathInfo("/etc/mtab").mtime();
276 if( mtime <= 0)
277 {
278 WAR << "Failed to retrieve modification time of '/etc/mtab'"
279 << std::endl;
280 }
281 return mtime;
282 }
283
284 static inline MountEntries
286 {
287 return Mount::getEntries();
288 }
289
290 };
291
292
294 // STATIC
296
297
300 {
301 if( !m_impl)
302 {
303 m_impl.reset( new MediaManager_Impl());
304 }
305 }
306
307 // ---------------------------------------------------------------
309 {
310 }
311
312 // ---------------------------------------------------------------
314 MediaManager::open(const Url &url, const Pathname &preferred_attach_point)
315 {
316 // create new access handler for it
318 ManagedMedia tmp = ManagedMedia::makeManagedMedia( url, preferred_attach_point, verifier );
319
320 MediaAccessId nextId = m_impl->nextAccessId();
321
322 m_impl->mediaMap.insert( std::make_pair( nextId, std::move(tmp) ) );
323 //m_impl->mediaMap[nextId] = std::move(tmp);
324
325 DBG << "Opened new media access using id " << nextId
326 << " to " << url.asString() << std::endl;
327 return nextId;
328 }
329
330 // ---------------------------------------------------------------
331 void
333 {
334 //
335 // The MediaISO handler internally requests an accessId
336 // of a "parent" handler providing the iso file.
337 // The parent handler accessId is private to MediaISO,
338 // but the attached media source may be shared reference.
339 // This means, that if the accessId exactly matches the
340 // parent handler id, close was used on uninitialized
341 // accessId variable (or the accessId was guessed) and
342 // the close request to this id will be rejected here.
343 //
344 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
345 for( ; m != m_impl->mediaMap.end(); ++m)
346 {
347 if( m->second.handler().dependsOnParent(accessId, true))
348 {
349 ZYPP_THROW(MediaIsSharedException(
350 m->second.handler().url().asString()
351 ));
352 }
353 }
354
355 DBG << "Close to access handler using id "
356 << accessId << " requested" << std::endl;
357
358 ManagedMedia &ref( m_impl->findMM(accessId));
359 ref.close();
360
361 m_impl->mediaMap.erase(accessId);
362 }
363
364 // ---------------------------------------------------------------
365 bool
367 {
368 ManagedMediaMap::iterator it( m_impl->mediaMap.find(accessId));
369 return it != m_impl->mediaMap.end();
370 }
371
372 // ---------------------------------------------------------------
373 std::string
375 {
376 ManagedMedia &ref( m_impl->findMM(accessId));
377
378 return ref.handler().protocol();
379 }
380
381 // ---------------------------------------------------------------
382 bool
384 {
385 ManagedMedia &ref( m_impl->findMM(accessId));
386
387 return ref.handler().downloads();
388 }
389
390 // ---------------------------------------------------------------
391 Url
393 {
394 ManagedMedia &ref( m_impl->findMM(accessId));
395
396 return ref.handler().url();
397 }
398
399 // ---------------------------------------------------------------
400 void
403 {
404 if( !verifier)
405 ZYPP_THROW(MediaException("Invalid verifier reference"));
406
407 ManagedMedia &ref( m_impl->findMM(accessId));
408
409 ref.desired = false;
410 MediaVerifierRef(verifier).swap(ref.verifier);
411
412 DBG << "MediaVerifier change: id=" << accessId << ", verifier="
413 << verifier->info() << std::endl;
414 }
415
416 // ---------------------------------------------------------------
417 void
419 {
420 ManagedMedia &ref( m_impl->findMM(accessId));
421
423 ref.desired = false;
424 ref.verifier.swap(verifier);
425
426 DBG << "MediaVerifier change: id=" << accessId << ", verifier="
427 << verifier->info() << std::endl;
428 }
429
430 // ---------------------------------------------------------------
431 bool
433 {
434 return MediaHandler::setAttachPrefix(attach_prefix);
435 }
436
437 // ---------------------------------------------------------------
439 {
440 ManagedMedia &ref( m_impl->findMM(accessId));
441 auto &hdl = ref.handler();
442
443 DBG << "attach(id=" << accessId << ")" << std::endl;
444
445 // try first mountable/mounted device
446 hdl.attach(false);
447 try
448 {
449 ref.checkDesired(accessId);
450 return;
451 }
452 catch (const MediaException & ex)
453 {
454 ZYPP_CAUGHT(ex);
455
456 if (!hdl.hasMoreDevices())
457 ZYPP_RETHROW(ex);
458
459 if (hdl.isAttached())
460 hdl.release();
461 }
462
463 MIL << "checkDesired(" << accessId << ") of first device failed,"
464 " going to try others with attach(true)" << std::endl;
465
466 while (hdl.hasMoreDevices())
467 {
468 try
469 {
470 // try to attach next device
471 hdl.attach(true);
472 ref.checkDesired(accessId);
473 return;
474 }
475 catch (const MediaNotDesiredException & ex)
476 {
477 ZYPP_CAUGHT(ex);
478
479 if (!hdl.hasMoreDevices())
480 {
481 MIL << "No desired media found after trying all detected devices." << std::endl;
482 ZYPP_RETHROW(ex);
483 }
484
485 AttachedMedia media(hdl.attachedMedia());
486 DBG << "Skipping " << media.mediaSource->asString() << ": not desired media." << std::endl;
487
488 hdl.release();
489 }
490 catch (const MediaException & ex)
491 {
492 ZYPP_CAUGHT(ex);
493
494 if (!hdl.hasMoreDevices())
495 ZYPP_RETHROW(ex);
496
497 AttachedMedia media(hdl.attachedMedia());
498 DBG << "Skipping " << media.mediaSource->asString() << " because of exception thrown by attach(true)" << std::endl;
499
500 if (hdl.isAttached()) hdl.release();
501 }
502 }
503 }
504
505 // ---------------------------------------------------------------
506 void
507 MediaManager::release(MediaAccessId accessId, const std::string & ejectDev)
508 {
509 ManagedMedia &ref( m_impl->findMM(accessId));
510
511 DBG << "release(id=" << accessId;
512 if (!ejectDev.empty())
513 DBG << ", " << ejectDev;
514 DBG << ")" << std::endl;
515
516 if(!ejectDev.empty())
517 {
518 //
519 // release MediaISO handlers, that are using the one
520 // specified with accessId, because it provides the
521 // iso file and it will disappear now (forced release
522 // with eject).
523 //
524 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
525 for( ; m != m_impl->mediaMap.end(); ++m)
526 {
527 auto &hdl = m->second.handler();
528 if( hdl.dependsOnParent(accessId, false))
529 {
530 try
531 {
532 DBG << "Forcing release of handler depending on access id "
533 << accessId << std::endl;
534 m->second.desired = false;
535 hdl.release();
536 }
537 catch(const MediaException &e)
538 {
539 ZYPP_CAUGHT(e);
540 }
541 }
542 }
543 }
544 ref.desired = false;
545 ref.handler().release(ejectDev);
546 }
547
548 // ---------------------------------------------------------------
549 void
551 {
552 MIL << "Releasing all attached media" << std::endl;
553
554 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
555 for( ; m != m_impl->mediaMap.end(); ++m)
556 {
557 auto &hdl = m->second.handler();
558 if( hdl.dependsOnParent())
559 continue;
560
561 try
562 {
563 if(hdl.isAttached())
564 {
565 DBG << "Releasing media id " << m->first << std::endl;
566 m->second.desired = false;
567 hdl.release();
568 }
569 else
570 {
571 DBG << "Media id " << m->first << " not attached " << std::endl;
572 }
573 }
574 catch(const MediaException & e)
575 {
576 ZYPP_CAUGHT(e);
577 ERR << "Failed to release media id " << m->first << std::endl;
578 }
579 }
580
581 MIL << "Exit" << std::endl;
582 }
583
584 // ---------------------------------------------------------------
585 void
587 {
588 ManagedMedia &ref( m_impl->findMM(accessId));
589
590 ref.handler().disconnect();
591 }
592
593 // ---------------------------------------------------------------
594 bool
596 {
597 ManagedMedia &ref( m_impl->findMM(accessId));
598
599 return ref.handler().isAttached();
600 }
601
602 // ---------------------------------------------------------------
604 {
605 ManagedMedia &ref( m_impl->findMM(accessId));
606
607 return ref.handler().isSharedMedia();
608 }
609
610 // ---------------------------------------------------------------
611 bool
613 {
614 ManagedMedia &ref( m_impl->findMM(accessId));
615
616 if( !ref.handler().isAttached())
617 {
618 ref.desired = false;
619 }
620 else
621 {
622 try {
623 ref.desired = ref.verifier->isDesiredMedia( ref.handler() );
624 }
625 catch(const zypp::Exception &e) {
626 ZYPP_CAUGHT(e);
627 ref.desired = false;
628 }
629 }
630 DBG << "isDesiredMedia(" << accessId << "): "
631 << (ref.desired ? "" : "not ")
632 << "desired (report by "
633 << ref.verifier->info() << ")" << std::endl;
634 return ref.desired;
635 }
636
637 // ---------------------------------------------------------------
638 bool
640 const MediaVerifierRef &verifier) const
641 {
643 if( !v)
644 ZYPP_THROW(MediaException("Invalid verifier reference"));
645
646 ManagedMedia &ref( m_impl->findMM(accessId));
647
648 bool desired = false;
649 if( ref.handler().isAttached())
650 {
651 try {
652 desired = v->isDesiredMedia( ref.handler() );
653 }
654 catch(const zypp::Exception &e) {
655 ZYPP_CAUGHT(e);
656 desired = false;
657 }
658 }
659 DBG << "isDesiredMedia(" << accessId << "): "
660 << (desired ? "" : "not ")
661 << "desired (report by "
662 << v->info() << ")" << std::endl;
663 return desired;
664 }
665
666 // ---------------------------------------------------------------
667 bool
669 {
670 return url(accessId).getScheme() == "cd" || url(accessId).getScheme() == "dvd";
671 }
672
673 // ---------------------------------------------------------------
676 {
677 ManagedMedia &ref( m_impl->findMM(accessId));
678
679 Pathname path;
680 path = ref.handler().localRoot();
681 return path;
682 }
683
684 // ---------------------------------------------------------------
687 const Pathname & pathname) const
688 {
689 ManagedMedia &ref( m_impl->findMM(accessId));
690
691 Pathname path;
692 path = ref.handler().localPath(pathname);
693 return path;
694 }
695
696 void
698 const Pathname &filename,
699 const ByteCount &expectedFileSize ) const
700 {
701 ManagedMedia &ref( m_impl->findMM(accessId));
702
703 auto loc = OnMediaLocation( filename )
704 .setDownloadSize( expectedFileSize )
705 .setDeltafile( ref.deltafile );
706
707 provideFile( accessId, loc );
708 }
709
710 // ---------------------------------------------------------------
711 void
713 const Pathname &filename ) const
714 {
715 ManagedMedia &ref( m_impl->findMM(accessId));
716
717 auto loc = OnMediaLocation( filename )
718 .setDeltafile( ref.deltafile );
719
720 provideFile( accessId, loc );
721 }
722
723 void MediaManager::provideFile( MediaAccessId accessId, const OnMediaLocation &file ) const
724 {
725 ManagedMedia &ref( m_impl->findMM(accessId));
726
727 ref.checkDesired(accessId);
728
729 ref.handler().provideFile( file );
730 }
731
732 // ---------------------------------------------------------------
733 void
735 const Pathname &filename ) const
736 {
737 ManagedMedia &ref( m_impl->findMM(accessId));
738
739 ref.checkDesired(accessId);
740
741 ref.deltafile = filename;
742 }
743
744 void MediaManager::precacheFiles(MediaAccessId accessId, const std::vector<OnMediaLocation> &files)
745 {
746 ManagedMedia &ref( m_impl->findMM(accessId));
747
748 ref.checkDesired(accessId);
749
750 ref.handler().precacheFiles( files );
751 }
752
753 // ---------------------------------------------------------------
754 void
756 const Pathname &dirname) const
757 {
758 ManagedMedia &ref( m_impl->findMM(accessId));
759
760 ref.checkDesired(accessId);
761
762 ref.handler().provideDir(dirname);
763 }
764
765 // ---------------------------------------------------------------
766 void
768 const Pathname &dirname) const
769 {
770 ManagedMedia &ref( m_impl->findMM(accessId));
771
772 ref.checkDesired(accessId);
773
774 ref.handler().provideDirTree(dirname);
775 }
776
777 // ---------------------------------------------------------------
778 void
780 const Pathname &filename) const
781 {
782 ManagedMedia &ref( m_impl->findMM(accessId));
783
784 ref.checkAttached(accessId);
785
786 ref.handler().releaseFile(filename);
787 }
788
789 // ---------------------------------------------------------------
790 void
792 const Pathname &dirname) const
793 {
794 ManagedMedia &ref( m_impl->findMM(accessId));
795
796 ref.checkAttached(accessId);
797
798 ref.handler().releaseDir(dirname);
799 }
800
801
802 // ---------------------------------------------------------------
803 void
805 const Pathname &pathname) const
806 {
807 ManagedMedia &ref( m_impl->findMM(accessId));
808
809 ref.checkAttached(accessId);
810
811 ref.handler().releasePath(pathname);
812 }
813
814 // ---------------------------------------------------------------
815 void
817 std::list<std::string> &retlist,
818 const Pathname &dirname,
819 bool dots) const
820 {
821 ManagedMedia &ref( m_impl->findMM(accessId));
822
823 // FIXME: ref.checkDesired(accessId); ???
824 ref.checkAttached(accessId);
825
826 ref.handler().dirInfo(retlist, dirname, dots);
827 }
828
829 // ---------------------------------------------------------------
830 void
832 filesystem::DirContent &retlist,
833 const Pathname &dirname,
834 bool dots) const
835 {
836 ManagedMedia &ref( m_impl->findMM(accessId));
837
838 // FIXME: ref.checkDesired(accessId); ???
839 ref.checkAttached(accessId);
840
841 ref.handler().dirInfo(retlist, dirname, dots);
842 }
843
844 // ---------------------------------------------------------------
845 bool
846 MediaManager::doesFileExist(MediaAccessId accessId, const Pathname & filename ) const
847 {
848 ManagedMedia &ref( m_impl->findMM(accessId));
849
850 // FIXME: ref.checkDesired(accessId); ???
851 ref.checkAttached(accessId);
852
853 return ref.handler().doesFileExist(filename);
854 }
855
856 // ---------------------------------------------------------------
857 void
859 std::vector<std::string> & devices,
860 unsigned int & index) const
861 {
862 ManagedMedia &ref( m_impl->findMM(accessId));
863 return ref.handler().getDetectedDevices(devices, index);
864 }
865
866 // ---------------------------------------------------------------
867 // STATIC
868 time_t
870 {
872 }
873
874 // ---------------------------------------------------------------
875 // STATIC
876 MountEntries
878 {
880 }
881
882 // ---------------------------------------------------------------
883 bool
885 bool mtab) const
886 {
887 if( path.empty() || path == "/" || !PathInfo(path).isDir())
888 return false;
889
890 //
891 // check against our current attach points
892 //
893 ManagedMediaMap::const_iterator m(m_impl->mediaMap.begin());
894 for( ; m != m_impl->mediaMap.end(); ++m)
895 {
896 AttachedMedia ret = m->second.handler().attachedMedia();
897 if( ret.mediaSource && ret.attachPoint)
898 {
899 std::string mnt(ret.attachPoint->path.asString());
900 std::string our(path.asString());
901
902 if( our == mnt)
903 {
904 // already used as attach point
905 return false;
906 }
907 else
908 if( mnt.size() > our.size() &&
909 mnt.at(our.size()) == '/' &&
910 !mnt.compare(0, our.size(), our))
911 {
912 // mountpoint is bellow of path
913 // (would hide the content)
914 return false;
915 }
916 }
917 }
918
919 if( !mtab)
920 return true;
921
922 //
923 // check against system mount entries
924 //
925 MountEntries entries( m_impl->getMountEntries());
926 MountEntries::const_iterator e;
927 for( e = entries.begin(); e != entries.end(); ++e)
928 {
929 std::string mnt(Pathname(e->dir).asString());
930 std::string our(path.asString());
931
932 if( our == mnt)
933 {
934 // already used as mountpoint
935 return false;
936 }
937 else
938 if( mnt.size() > our.size() &&
939 mnt.at(our.size()) == '/' &&
940 !mnt.compare(0, our.size(), our))
941 {
942 // mountpoint is bellow of path
943 // (would hide the content)
944 return false;
945 }
946 }
947
948 return true;
949 }
950
951 // ---------------------------------------------------------------
954 {
955 ManagedMedia &ref( m_impl->findMM(accessId));
956
957 return ref.handler().attachedMedia();
958 }
959
960 // ---------------------------------------------------------------
963 {
964 if( !media || media->type.empty())
965 return AttachedMedia();
966
967 ManagedMediaMap::const_iterator m(m_impl->mediaMap.begin());
968 for( ; m != m_impl->mediaMap.end(); ++m)
969 {
970 if( !m->second.handler().isAttached())
971 continue;
972
973 AttachedMedia ret = m->second.handler().attachedMedia();
974 if( ret.mediaSource && ret.mediaSource->equals( *media))
975 return ret;
976 }
977 return AttachedMedia();
978 }
979
980 // ---------------------------------------------------------------
981 void
983 {
984 if( !media || media->type.empty())
985 return;
986
987 ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
988 for( ; m != m_impl->mediaMap.end(); ++m)
989 {
990 if( !m->second.handler().isAttached())
991 continue;
992
993 AttachedMedia ret = m->second.handler().attachedMedia();
994 if( ret.mediaSource && ret.mediaSource->equals( *media))
995 {
996 m->second.handler().release();
997 m->second.desired = false;
998 }
999 }
1000 }
1001
1003 } // namespace media
1005
1007} // namespace zypp
1009/*
1010** vim: set ts=2 sts=2 sw=2 ai et:
1011*/
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
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.
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
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 OnMediaLocation &obj)
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:430
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:426
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:418
#define DBG
Definition: Logger.h:95
#define MIL
Definition: Logger.h:96
#define ERR
Definition: Logger.h:98
#define WAR
Definition: Logger.h:97