// STATIC
static Mutex g_Mutex;
+ /*
+ ** Use a map<ID, struct { handler, verifier, isVerified }> ?
+ */
+ enum MediaVerifyState
+ {
+ NOT_VERIFIED, VERIFIED
+ };
+
typedef std::map<MediaAccessId, MediaVerifierRef> MediaVfyMap;
typedef std::map<MediaAccessId, MediaAccessRef> MediaAccMap;
-
+ typedef std::map<MediaAccessId, MediaVerifyState> MediaVStMap;
////////////////////////////////////////////////////////////////
} // anonymous
public:
MediaVfyMap mediaVfyMap;
MediaAccMap mediaAccMap;
+ MediaVStMap mediaVStMap;
Impl()
: mtab_mtime(0)
m_impl->mediaAccMap[nextId] = accRef;
m_impl->mediaVfyMap[nextId] = vfyRef;
+ m_impl->mediaVStMap[nextId] = NOT_VERIFIED;
DBG << "Opened new media access using id " << nextId
<< " to " << url.asString() << std::endl;
}
// ---------------------------------------------------------------
+ /*
void
MediaManager::reopen(MediaAccessId accessId, const Url &url,
const Pathname & preferred_attach_point)
// assign new one
m_impl->mediaAccMap[accessId] = accRef;
+ m_impl->mediaVStMap[accessId] = NOT_VERIFIED;
DBG << "Reopened media access id " << accessId
<< " to " << url.asString() << std::endl;
}
-
+ */
+
// ---------------------------------------------------------------
/*
bool
if( m_impl->hasMediaAcc(idOne) && m_impl->hasMediaAcc(idTwo))
{
+ // FIXME: swich verifier and its state as well
MediaAccessRef tmp( m_impl->mediaAccMap[idOne]);
m_impl->mediaAccMap[idOne] = m_impl->mediaAccMap[idTwo];
m_impl->mediaAccMap[accessId]->close();
m_impl->mediaAccMap.erase(accessId);
m_impl->mediaVfyMap.erase(accessId);
+ m_impl->mediaVStMap.erase(accessId);
}
// ---------------------------------------------------------------
}
// ---------------------------------------------------------------
+#if 0
void
- MediaManager::attachMediaNr(MediaAccessId accessId,
- MediaNr mediaNr,
- bool eject)
+ MediaManager::attachDesiredMedia(MediaAccessId accessId,
+ bool eject)
{
MutexLock glock(g_Mutex);
));
}
+ // 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
// ---------------------------------------------------------------
bool
- MediaManager::isDesiredMedia(MediaAccessId accessId, MediaNr mediaNr) const
+ MediaManager::isDesiredMedia(MediaAccessId accessId) const
{
MutexLock glock(g_Mutex);
bool ok;
try {
ok = m_impl->mediaVfyMap[accessId]->isDesiredMedia(
- m_impl->mediaAccMap[accessId], mediaNr
+ m_impl->mediaAccMap[accessId]
);
}
- catch( ... ) { ok = false; }
+ catch(const zypp::Exception &e) {
+ ZYPP_CAUGHT(e);
+ ok = false;
+ }
return ok;
}
// ---------------------------------------------------------------
bool
MediaManager::isDesiredMedia(MediaAccessId accessId,
- MediaNr mediaNr,
const MediaVerifierRef &verifier) const
{
MutexLock glock(g_Mutex);
bool ok;
try {
ok = v->isDesiredMedia(
- m_impl->mediaAccMap[accessId], mediaNr
+ m_impl->mediaAccMap[accessId]
);
}
- catch( ... ) { ok = false; }
+ catch(const zypp::Exception &e) {
+ ZYPP_CAUGHT(e);
+ ok = false;
+ }
return ok;
}
// ---------------------------------------------------------------
void
MediaManager::provideFile(MediaAccessId accessId,
- MediaNr mediaNr,
const Pathname &filename,
bool cached,
bool checkonly) const
{
MutexLock glock(g_Mutex);
- if( !isDesiredMedia(accessId, mediaNr))
+ // FIXME: cache the results
+ /*
+ if( !isDesiredMedia(accessId))
{
ZYPP_THROW(MediaNotDesiredException(
- m_impl->mediaAccMap[accessId]->url(), mediaNr
- ));
- }
-
- m_impl->mediaAccMap[accessId]->provideFile(filename, cached, checkonly);
- }
-
- // ---------------------------------------------------------------
- void
- MediaManager::provideFile(MediaAccessId accessId,
- const Pathname &filename,
- bool cached,
- bool checkonly) const
- {
- MutexLock glock(g_Mutex);
-
- if( !m_impl->hasMediaAcc( accessId))
- {
- ZYPP_THROW(MediaNotOpenException(
- "Invalid media access id " + str::numstring(accessId)
+ m_impl->mediaAccMap[accessId]->url()
));
}
+ */
m_impl->mediaAccMap[accessId]->provideFile(filename, cached, checkonly);
}
// ---------------------------------------------------------------
void
MediaManager::provideDir(MediaAccessId accessId,
- MediaNr mediaNr,
const Pathname &dirname) const
{
MutexLock glock(g_Mutex);
- if( !isDesiredMedia(accessId, mediaNr))
+ // FIXME: cache the results
+ /*
+ if( !isDesiredMedia(accessId))
{
ZYPP_THROW(MediaNotDesiredException(
- m_impl->mediaAccMap[accessId]->url(), mediaNr
- ));
- }
-
- m_impl->mediaAccMap[accessId]->provideDir(dirname);
- }
-
- // ---------------------------------------------------------------
- void
- MediaManager::provideDir(MediaAccessId accessId,
- const Pathname &dirname) const
- {
- MutexLock glock(g_Mutex);
-
- if( !m_impl->hasMediaAcc( accessId))
- {
- ZYPP_THROW(MediaNotOpenException(
- "Invalid media access id " + str::numstring(accessId)
+ m_impl->mediaAccMap[accessId]->url()
));
}
+ */
m_impl->mediaAccMap[accessId]->provideDir(dirname);
}
// ---------------------------------------------------------------
void
MediaManager::provideDirTree(MediaAccessId accessId,
- MediaNr mediaNr,
const Pathname &dirname) const
{
MutexLock glock(g_Mutex);
- if( !isDesiredMedia(accessId, mediaNr))
+ // FIXME: cache the results
+ /*
+ if( !isDesiredMedia(accessId))
{
ZYPP_THROW(MediaNotDesiredException(
- m_impl->mediaAccMap[accessId]->url(), mediaNr
- ));
- }
-
- m_impl->mediaAccMap[accessId]->provideDirTree(dirname);
- }
-
- // ---------------------------------------------------------------
- void
- MediaManager::provideDirTree(MediaAccessId accessId,
- const Pathname &dirname) const
- {
- MutexLock glock(g_Mutex);
-
- if( !m_impl->hasMediaAcc( accessId))
- {
- ZYPP_THROW(MediaNotOpenException(
- "Invalid media access id " + str::numstring(accessId)
+ m_impl->mediaAccMap[accessId]->url()
));
}
+ */
m_impl->mediaAccMap[accessId]->provideDirTree(dirname);
}
{
MutexLock glock(g_Mutex);
+ // FIXME: check isDesiredMedia(accessId) ???
if( !m_impl->hasMediaAcc( accessId))
{
ZYPP_THROW(MediaNotOpenException(
{
MutexLock glock(g_Mutex);
+ // FIXME: check isDesiredMedia(accessId) ???
if( !m_impl->hasMediaAcc( accessId))
{
ZYPP_THROW(MediaNotOpenException(
{
MutexLock glock(g_Mutex);
+ // FIXME: check isDesiredMedia(accessId) ???
if( !m_impl->hasMediaAcc( accessId))
{
ZYPP_THROW(MediaNotOpenException(
{
MutexLock glock(g_Mutex);
+ // FIXME: check isDesiredMedia(accessId) ???
if( !m_impl->hasMediaAcc( accessId))
{
ZYPP_THROW(MediaNotOpenException(
{
MutexLock glock(g_Mutex);
+ // FIXME: check isDesiredMedia(accessId) ???
if( !m_impl->hasMediaAcc( accessId))
{
ZYPP_THROW(MediaNotOpenException(
#include <zypp/media/MediaAccess.h>
#include <zypp/base/NonCopyable.h>
-#include <zypp/base/Deprecated.h>
#include <zypp/base/PtrTypes.h>
#include <zypp/Pathname.h>
#include <zypp/Url.h>
///////////////////////////////////////////////////////////////////
typedef zypp::RW_pointer<MediaAccess> MediaAccessRef;
typedef unsigned int MediaAccessId;
+
+ // OBSOLETE HERE:
typedef MediaAccessId MediaId;
typedef unsigned int MediaNr;
/*
** Check if the specified attached media contains
- ** the desired media number (e.g. SLES10 CD1).
+ ** the desired media (e.g. SLES10 CD1).
*/
virtual bool
- isDesiredMedia(const MediaAccessRef &ref, MediaNr mediaNr)
- {
- return false;
- }
+ isDesiredMedia(const MediaAccessRef &ref) = 0;
};
** the desired media number. Always return true.
*/
virtual bool
- isDesiredMedia(const MediaAccessRef &ref, MediaNr mediaNr)
+ isDesiredMedia(const MediaAccessRef &ref)
{
+ (void)ref;
return true;
}
};
/**
* 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.
attach(MediaAccessId accessId, bool next = false);
/**
+ * FIXME: Jiri, do you want this one?
+ *
* Attach the media if needed and verify, if desired
- * media number is avaliable. If the access handler
- * supports multiple drives (e.g. CD/DVD), all drives
- * are verified.
+ * 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
- attachMediaNr(MediaAccessId accessId, MediaNr mediaNr,
- bool eject = true);
+ attachDesiredMedia(MediaAccessId accessId, bool eject = true);
+ */
/**
* Release the attached media and optionally eject.
- * \throws exception if eject is true and media is
- * shared.
+ * \throws MediaIsSharedException if eject is true
+ * and media is shared.
*/
void
release(MediaAccessId accessId, bool eject = false);
* \return True if desired media is attached.
*/
bool
- isDesiredMedia(MediaAccessId accessId, MediaNr mediaNr) const;
+ isDesiredMedia(MediaAccessId accessId) const;
/**
* Ask the specified verifier if the attached
* \return True if desired media is attached.
*/
bool
- isDesiredMedia(MediaAccessId accessId, MediaNr mediaNr,
+ isDesiredMedia(MediaAccessId accessId,
const MediaVerifierRef &verifier) const;
/**
* on the media.
*
* \param accessId The media access id to use.
- * \param mediaNr The desired media number that should be on the media.
* \param cached If cached is set to true, the function checks, if
* the file already exists and doesn't download it again
* if it does. Currently only the existence is checked,
* returned always.
*
* \throws MediaException
- *
- * \deprecated checking the media number on each access.
*/
void
- provideFile(MediaAccessId accessId,
- MediaNr mediaNr,
- const Pathname &filename,
- bool cached = false,
- bool checkonly = false) const ZYPP_DEPRECATED;
-
- void
provideFile(MediaAccessId accessId,
const Pathname &filename,
bool cached = false,
bool checkonly = false) const;
/**
- * \deprecated checking the media number on each access.
*/
void
- provideDir(MediaAccessId accessId,
- MediaNr mediaNr,
- const Pathname &dirname) const ZYPP_DEPRECATED;
-
- void
provideDir(MediaAccessId accessId,
const Pathname &dirname) const;
/**
- * \deprecated checking the media number on each access.
*/
void
- provideDirTree(MediaAccessId accessId,
- MediaNr mediaNr,
- const Pathname &dirname) const ZYPP_DEPRECATED;
-
- void
provideDirTree(MediaAccessId accessId,
const Pathname &dirname) const;
/**
- * \deprecated checking the media number on each access.
*/
void
releaseFile(MediaAccessId accessId,