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