libzypp  17.3.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 
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
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 
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  // ---------------------------------------------------------------
672  void
674  const Pathname &filename ) 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);
683  }
684 
685  // ---------------------------------------------------------------
686  void
688  const Pathname &filename ) const
689  {
690  MutexLock glock(g_Mutex);
691 
692  ManagedMedia &ref( m_impl->findMM(accessId));
693 
694  ref.checkDesired(accessId);
695 
696  ref.handler->setDeltafile(filename);
697  }
698 
699  // ---------------------------------------------------------------
700  void
702  const Pathname &dirname) const
703  {
704  MutexLock glock(g_Mutex);
705 
706  ManagedMedia &ref( m_impl->findMM(accessId));
707 
708  ref.checkDesired(accessId);
709 
710  ref.handler->provideDir(dirname);
711  }
712 
713  // ---------------------------------------------------------------
714  void
716  const Pathname &dirname) const
717  {
718  MutexLock glock(g_Mutex);
719 
720  ManagedMedia &ref( m_impl->findMM(accessId));
721 
722  ref.checkDesired(accessId);
723 
724  ref.handler->provideDirTree(dirname);
725  }
726 
727  // ---------------------------------------------------------------
728  void
730  const Pathname &filename) const
731  {
732  MutexLock glock(g_Mutex);
733 
734  ManagedMedia &ref( m_impl->findMM(accessId));
735 
736  ref.checkAttached(accessId);
737 
738  ref.handler->releaseFile(filename);
739  }
740 
741  // ---------------------------------------------------------------
742  void
744  const Pathname &dirname) const
745  {
746  MutexLock glock(g_Mutex);
747 
748  ManagedMedia &ref( m_impl->findMM(accessId));
749 
750  ref.checkAttached(accessId);
751 
752  ref.handler->releaseDir(dirname);
753  }
754 
755 
756  // ---------------------------------------------------------------
757  void
759  const Pathname &pathname) const
760  {
761  MutexLock glock(g_Mutex);
762 
763  ManagedMedia &ref( m_impl->findMM(accessId));
764 
765  ref.checkAttached(accessId);
766 
767  ref.handler->releasePath(pathname);
768  }
769 
770  // ---------------------------------------------------------------
771  void
773  std::list<std::string> &retlist,
774  const Pathname &dirname,
775  bool dots) const
776  {
777  MutexLock glock(g_Mutex);
778 
779  ManagedMedia &ref( m_impl->findMM(accessId));
780 
781  // FIXME: ref.checkDesired(accessId); ???
782  ref.checkAttached(accessId);
783 
784  ref.handler->dirInfo(retlist, dirname, dots);
785  }
786 
787  // ---------------------------------------------------------------
788  void
790  filesystem::DirContent &retlist,
791  const Pathname &dirname,
792  bool dots) const
793  {
794  MutexLock glock(g_Mutex);
795 
796  ManagedMedia &ref( m_impl->findMM(accessId));
797 
798  // FIXME: ref.checkDesired(accessId); ???
799  ref.checkAttached(accessId);
800 
801  ref.handler->dirInfo(retlist, dirname, dots);
802  }
803 
804  // ---------------------------------------------------------------
805  bool
806  MediaManager::doesFileExist(MediaAccessId accessId, const Pathname & filename ) const
807  {
808  MutexLock glock(g_Mutex);
809  ManagedMedia &ref( m_impl->findMM(accessId));
810 
811  // FIXME: ref.checkDesired(accessId); ???
812  ref.checkAttached(accessId);
813 
814  return ref.handler->doesFileExist(filename);
815  }
816 
817  // ---------------------------------------------------------------
818  void
820  std::vector<std::string> & devices,
821  unsigned int & index) const
822  {
823  MutexLock glock(g_Mutex);
824  ManagedMedia &ref( m_impl->findMM(accessId));
825  return ref.handler->getDetectedDevices(devices, index);
826  }
827 
828  // ---------------------------------------------------------------
829  // STATIC
830  time_t
832  {
833  MutexLock glock(g_Mutex);
835  }
836 
837  // ---------------------------------------------------------------
838  // STATIC
839  MountEntries
841  {
842  MutexLock glock(g_Mutex);
843 
845  }
846 
847  // ---------------------------------------------------------------
848  bool
850  bool mtab) const
851  {
852  if( path.empty() || path == "/" || !PathInfo(path).isDir())
853  return false;
854 
855  MutexLock glock(g_Mutex);
856 
857  //
858  // check against our current attach points
859  //
860  ManagedMediaMap::const_iterator m(m_impl->mediaMap.begin());
861  for( ; m != m_impl->mediaMap.end(); ++m)
862  {
863  AttachedMedia ret = m->second.handler->attachedMedia();
864  if( ret.mediaSource && ret.attachPoint)
865  {
866  std::string mnt(ret.attachPoint->path.asString());
867  std::string our(path.asString());
868 
869  if( our == mnt)
870  {
871  // already used as attach point
872  return false;
873  }
874  else
875  if( mnt.size() > our.size() &&
876  mnt.at(our.size()) == '/' &&
877  !mnt.compare(0, our.size(), our))
878  {
879  // mountpoint is bellow of path
880  // (would hide the content)
881  return false;
882  }
883  }
884  }
885 
886  if( !mtab)
887  return true;
888 
889  //
890  // check against system mount entries
891  //
892  MountEntries entries( m_impl->getMountEntries());
893  MountEntries::const_iterator e;
894  for( e = entries.begin(); e != entries.end(); ++e)
895  {
896  std::string mnt(Pathname(e->dir).asString());
897  std::string our(path.asString());
898 
899  if( our == mnt)
900  {
901  // already used as mountpoint
902  return false;
903  }
904  else
905  if( mnt.size() > our.size() &&
906  mnt.at(our.size()) == '/' &&
907  !mnt.compare(0, our.size(), our))
908  {
909  // mountpoint is bellow of path
910  // (would hide the content)
911  return false;
912  }
913  }
914 
915  return true;
916  }
917 
918  // ---------------------------------------------------------------
921  {
922  MutexLock glock(g_Mutex);
923 
924  ManagedMedia &ref( m_impl->findMM(accessId));
925 
926  return ref.handler->attachedMedia();
927  }
928 
929  // ---------------------------------------------------------------
932  {
933  MutexLock glock(g_Mutex);
934 
935  if( !media || media->type.empty())
936  return AttachedMedia();
937 
938  ManagedMediaMap::const_iterator m(m_impl->mediaMap.begin());
939  for( ; m != m_impl->mediaMap.end(); ++m)
940  {
941  if( !m->second.handler->isAttached())
942  continue;
943 
944  AttachedMedia ret = m->second.handler->attachedMedia();
945  if( ret.mediaSource && ret.mediaSource->equals( *media))
946  return ret;
947  }
948  return AttachedMedia();
949  }
950 
951  // ---------------------------------------------------------------
952  void
954  {
955  MutexLock glock(g_Mutex);
956 
957  if( !media || media->type.empty())
958  return;
959 
960  ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
961  for( ; m != m_impl->mediaMap.end(); ++m)
962  {
963  if( !m->second.handler->isAttached())
964  continue;
965 
966  AttachedMedia ret = m->second.handler->attachedMedia();
967  if( ret.mediaSource && ret.mediaSource->equals( *media))
968  {
969  m->second.handler->release();
970  m->second.desired = false;
971  }
972  }
973  }
974 
976  } // namespace media
978 
980 } // namespace zypp
982 /*
983 ** vim: set ts=2 sts=2 sw=2 ai et:
984 */
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:527
Dummy default media verifier, which is always happy.
Definition: MediaManager.h:88
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
#define MIL
Definition: Logger.h:64
static time_t getMountTableMTime()
void releasePath(MediaAccessId accessId, const Pathname &pathname) const
FIXME: see MediaAccess class.
void provideDirTree(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
void setDeltafile(MediaAccessId accessId, const Pathname &filename) const
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
bool doesFileExist(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
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
void dirInfo(MediaAccessId accessId, std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
FIXME: see MediaAccess class.
time_t mtime() const
Definition: PathInfo.h:376
Url url
Definition: MediaCurl.cc:196
bool isOpen(MediaAccessId accessId) const
Query if the media access is open / exists.
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&#39;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:913
virtual std::string info() const
Returns a string with some info about the verifier.
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for &#39;localRoot() + pathname&#39;, but returns an empty pathname if media is not attached...
~MediaManager()
Destroys MediaManager envelope instance.
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
bool empty() const
Test for an empty path.
Definition: Pathname.h:113
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:400
AttachPointRef attachPoint
Definition: MediaSource.h:145
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:491
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
const std::string & asString() const
String representation.
Definition: Pathname.h:90
Just inherits Exception to separate media exceptions.
ManagedMedia & findMM(MediaAccessId accessId)
static bool setAttachPrefix(const Pathname &attach_prefix)
#define WAR
Definition: Logger.h:65
bool hasId(MediaAccessId accessId) const
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 getAttachedMedia(MediaAccessId &accessId) const
std::string numstring(char n, int w=0)
Definition: String.h:288
void provideDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
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.
void releaseDir(MediaAccessId accessId, const Pathname &dirname) const
FIXME: see MediaAccess class.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:396
Url url(MediaAccessId accessId) const
Returns the Media Access Url of the media access id.
A recursive Mutex.
Definition: Mutex.h:35
Manages access to the &#39;physical&#39; media, e.g CDROM drives, Disk volumes, directory trees...
Definition: MediaManager.h:473
bool isSharedMedia(MediaAccessId accessId) const
Returns information if media is on a shared physical device or not.
Base class for Exception.
Definition: Exception.h:145
static MountEntries getEntries(const std::string &mtab="")
Return mount entries from /etc/mtab or /etc/fstab file.
Definition: Mount.cc:275
bool downloads(MediaAccessId accessId) const
Hint if files are downloaded or not.
MediaVerifierRef verifier
virtual std::string info() const
Returns the "zypp::media::NoVerifier" string.
Wrapper for const correct access via Smart pointer types.
Definition: PtrTypes.h:285
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:220
bool isAttached(MediaAccessId accessId) const
Check if media is attached or not.
void releaseAll()
Release all attached media.
bool isDesiredMedia(MediaAccessId accessId) const
Ask the registered verifier if the attached media is the desired one 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 ...
Pathname localRoot(MediaAccessId accessId) const
Return the local directory that corresponds to medias url, no matter if media isAttached or not...
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
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 releaseFile(MediaAccessId accessId, const Pathname &filename) const
FIXME: see MediaAccess class.
void close(MediaAccessId accessId)
Close the media access with specified id.
#define DBG
Definition: Logger.h:63
std::string protocol(MediaAccessId accessId) const
Query the protocol name used by the media access handler.
static std::vector< MountEntry > getMountEntries()
Get current mount entries from /etc/mtab file.
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Check if the specified path is useable as attach point.
void provideFile(MediaAccessId accessId, const Pathname &filename) const
Provide provide file denoted by relative path below of the &#39;attach point&#39; of the specified media and ...