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