, verifier(m.verifier)
{}
- ManagedMedia(MediaAccess *h, MediaVerifierBase *v)
+ ManagedMedia(const MediaAccessRef &h, const MediaVerifierRef &v)
: desired (false)
, handler (h)
, verifier(v)
Impl()
: mtab_mtime(0)
+ , mtab_table()
, last_accessid(0)
{}
~Impl()
- {}
+ {
+ try
+ {
+ mtab_table.clear();
+ mediaMap.clear();
+ }
+ catch( ... )
+ {}
+ }
inline MediaAccessId
nextAccessId()
return it->second;
}
+ inline time_t
+ getMountTableMTime() const
+ {
+ return zypp::PathInfo("/etc/mtab").mtime();
+ }
+
inline MountEntries
getMountEntries()
{
- if( mtab_mtime == 0 ||
- mtab_mtime != zypp::PathInfo("/etc/mtab").mtime())
+ time_t old = mtab_mtime;
+ mtab_mtime = getMountTableMTime();
+ if( old <= 0 || mtab_mtime != old)
{
mtab_table = Mount::getEntries("/etc/mtab");
}
return mtab_table;
}
+
};
MutexLock glock(g_Mutex);
// create new access handler for it
- ManagedMedia tmp( new MediaAccess(), new NoVerifier());
+ MediaAccessRef handler( new MediaAccess());
+ MediaVerifierRef verifier( new NoVerifier());
+ ManagedMedia tmp( handler, verifier);
tmp.handler->open(url, preferred_attach_point);
}
// ---------------------------------------------------------------
- /*
- void
- MediaManager::reopen(MediaAccessId accessId, const Url &url,
- const Pathname & preferred_attach_point)
- {
- MutexLock glock(g_Mutex);
-
- // FIXME: onbsolete
-
- ManagedMedia &ref( m_impl->findMM(accessId));
-
- ManagedMedia tmp( new MediaAccess(), new NoVerifier());
-
- tmp.handler->open(url, preferred_attach_point);
-
- // release and close the old one
- ref.handler->close();
-
- // assign new one
- ref = tmp;
-
- DBG << "Reopened media access id " << accessId
- << " to " << url.asString() << std::endl;
- }
- */
-
- // ---------------------------------------------------------------
- /*
- bool
- MediaManager::swap(MediaAccessId idOne, MediaAccessId idTwo)
- {
- MutexLock glock(g_Mutex);
-
- if( idOne != idTwo && m_impl->hasId(idOne) && m_impl->hasId(idTwo))
- {
- ManagedMedia tmp( m_impl->mediaMap[idOne]);
-
- m_impl->mediaMap[idOne] = m_impl->mediaMap[idTwo];
- m_impl->mediaMap[idTwo] = tmp;
-
- DBG << "Swapped media access ids "
- << idOne << " and " << idTwo << std::endl;
- return true;
- }
- return false;
- }
- */
-
- // ---------------------------------------------------------------
void
MediaManager::close(MediaAccessId accessId)
{
}
// ---------------------------------------------------------------
-#if 0
- void
- MediaManager::attachDesiredMedia(MediaAccessId accessId,
- bool eject)
- {
- MutexLock glock(g_Mutex);
-
- if( !m_impl->hasMediaAcc( accessId))
- {
- ZYPP_THROW(MediaNotOpenException(
- "Invalid media access id " + str::numstring(accessId)
- ));
- }
-
- // this should never happen, since we allways add a NoVerifier!
- if( !m_impl->hasVerifier( accessId))
- ZYPP_THROW(MediaException("Invalid verifier detected"));
-
- // check the attached media first..
- if( m_impl->mediaAccMap[accessId]->isAttached())
- {
- bool desired;
- try {
- desired = m_impl->mediaVfyMap[accessId]->isDesiredMedia(
- m_impl->mediaAccMap[accessId]
- );
- }
- catch(const zypp::Exception &e) {
- ZYPP_CAUGHT(e);
- desired = false;
- }
-
- if( desired) {
- // we found it already attached
- return;
- }
- else {
- try
- {
- m_impl->mediaAccMap[accessId]->release(eject);
- }
- /*
- ** FIXME: remember it for later
- **
- catch(const zypp::MediaIsSharedException &e) {
- ZYPP_CAUGHT(e);
- }
- */
- // allow to escape umount exceptions
- }
- }
-
- // FIXME: implement it.
- }
-#endif
-
- // ---------------------------------------------------------------
void
MediaManager::release(MediaAccessId accessId, bool eject)
{
ref.handler->dirInfo(retlist, dirname, dots);
}
+ // ---------------------------------------------------------------
+ time_t
+ MediaManager::getMountTableMTime() const
+ {
+ MutexLock glock(g_Mutex);
+
+ return m_impl->getMountTableMTime();
+ }
+
+ // ---------------------------------------------------------------
+ MountEntries
+ MediaManager::getMountEntries() const
+ {
+ MutexLock glock(g_Mutex);
+
+ return m_impl->getMountEntries();
+ }
// ---------------------------------------------------------------
AttachedMedia
///////////////////////////////////////////////////////////////////
+ class MountEntry;
+
+
+ ///////////////////////////////////////////////////////////////////
typedef zypp::RW_pointer<MediaAccess> MediaAccessRef;
typedef unsigned int MediaAccessId;
open(const Url &url, const Pathname & preferred_attach_point = "");
/**
- * Open new access handler with specifier url and attach
- * point reusing the specified accessId.
- void
- reopen(MediaAccessId accessId, const Url &url,
- const Pathname & preferred_attach_point = "");
- */
-
- /**
- * Swap access handlers of idOne and idTwo.
- *
- * \returns True, if idOne and and idTwo was both valid.
- bool
- swap(MediaAccessId idOne, MediaAccessId idTwo);
- */
-
- /**
* close the media
*/
void
attach(MediaAccessId accessId, bool next = false);
/**
- * FIXME: Jiri, do you want this one?
- *
- * Attach the media if needed and verify, if desired
- * media is avaliable. If the access handler supports
- * multiple drives (e.g. CD/DVD), all drives will be
- * verified.
- * On success, the media is attached and verified.
- * On failure, the media is released and optionally
- * ejected if possible (not shared).
- *
- * \throws MediaNotDesiredException if unable to find
- * desired media in any drive.
- * \throws FIXME if all drives are in use and no one
- * was ejected.
- void
- attachDesiredMedia(MediaAccessId accessId, bool eject = true);
- */
-
- /**
* Release the attached media and optionally eject.
* \throws MediaIsSharedException if eject is true
* and media is shared.
/**
*/
- void dirInfo(MediaAccessId accessId,
- std::list<std::string> &retlist,
- const Pathname &dirname,
- bool dots = true) const;
+ void
+ dirInfo(MediaAccessId accessId,
+ std::list<std::string> &retlist,
+ const Pathname &dirname,
+ bool dots = true) const;
/**
*/
- void dirInfo(MediaAccessId accessId,
- filesystem::DirContent &retlist,
- const Pathname &dirname,
- bool dots = true) const;
+ void
+ dirInfo(MediaAccessId accessId,
+ filesystem::DirContent &retlist,
+ const Pathname &dirname,
+ bool dots = true) const;
+
+
+ public:
+ time_t
+ getMountTableMTime() const;
+ std::vector<MountEntry>
+ getMountEntries() const;
private:
friend class MediaHandler;