}
// ---------------------------------------------------------------
+ void
+ MediaManager::disconnect(MediaId mediaId)
+ {
+ MutexLock lock(g_Mutex);
+
+ if( !m_impl->hasMediaAcc( mediaId))
+ {
+ ZYPP_THROW(MediaNotOpenException(
+ "Invalid media id " + str::numstring(mediaId)
+ ));
+ }
+ return m_impl->mediaAccMap[mediaId]->disconnect();
+ }
+
+ // ---------------------------------------------------------------
bool
MediaManager::isAttached(MediaId mediaId) const
{
}
// ---------------------------------------------------------------
+ Pathname
+ MediaManager::localRoot(MediaId mediaId) const
+ {
+ MutexLock lock(g_Mutex);
+
+ if( !m_impl->hasMediaAcc( mediaId))
+ {
+ ZYPP_THROW(MediaNotOpenException(
+ "Invalid media id " + str::numstring(mediaId)
+ ));
+ }
+ Pathname path;
+ path = m_impl->mediaAccMap[mediaId]->localRoot();
+ return path;
+ }
+
+ // ---------------------------------------------------------------
+ Pathname
+ MediaManager::localPath(MediaId mediaId,
+ const Pathname & pathname) const
+ {
+ MutexLock lock(g_Mutex);
+
+ if( !m_impl->hasMediaAcc( mediaId))
+ {
+ ZYPP_THROW(MediaNotOpenException(
+ "Invalid media id " + str::numstring(mediaId)
+ ));
+ }
+ Pathname path;
+ path = m_impl->mediaAccMap[mediaId]->localPath(pathname);
+ return path;
+ }
+
+ // ---------------------------------------------------------------
void
MediaManager::provideFile(MediaId mediaId, MediaNr mediaNr,
const Pathname &filename,
if( !isDesiredMedia(mediaId, mediaNr))
{
- ZYPP_THROW(MediaFileNotFoundException(
- m_impl->mediaAccMap[mediaId]->url(), filename
+ ZYPP_THROW(MediaNotDesiredException(
+ m_impl->mediaAccMap[mediaId]->url(), mediaNr
));
}
m_impl->mediaAccMap[mediaId]->provideFile(filename, cached, checkonly);
}
+ // ---------------------------------------------------------------
+ void
+ MediaManager::provideDir(MediaId mediaId,
+ MediaNr mediaNr,
+ const Pathname & dirname ) const
+ {
+ MutexLock lock(g_Mutex);
+
+ if( !isDesiredMedia(mediaId, mediaNr))
+ {
+ ZYPP_THROW(MediaNotDesiredException(
+ m_impl->mediaAccMap[mediaId]->url(), mediaNr
+ ));
+ }
+
+ m_impl->mediaAccMap[mediaId]->provideDir(dirname);
+ }
+
+ // ---------------------------------------------------------------
+ void
+ MediaManager::provideDirTree(MediaId mediaId,
+ MediaNr mediaNr,
+ const Pathname & dirname ) const
+ {
+ MutexLock lock(g_Mutex);
+
+ if( !isDesiredMedia(mediaId, mediaNr))
+ {
+ ZYPP_THROW(MediaNotDesiredException(
+ m_impl->mediaAccMap[mediaId]->url(), mediaNr
+ ));
+ }
+
+ m_impl->mediaAccMap[mediaId]->provideDirTree(dirname);
+ }
+
+ // ---------------------------------------------------------------
+ void
+ MediaManager::releaseFile(MediaId mediaId,
+ const Pathname & filename) const
+ {
+ if( !m_impl->hasMediaAcc( mediaId))
+ {
+ ZYPP_THROW(MediaNotOpenException(
+ "Invalid media id " + str::numstring(mediaId)
+ ));
+ }
+
+ m_impl->mediaAccMap[mediaId]->releaseFile(filename);
+ }
+
+ // ---------------------------------------------------------------
+ void
+ MediaManager::releaseDir(MediaId mediaId,
+ const Pathname & dirname) const
+ {
+ if( !m_impl->hasMediaAcc( mediaId))
+ {
+ ZYPP_THROW(MediaNotOpenException(
+ "Invalid media id " + str::numstring(mediaId)
+ ));
+ }
+
+ m_impl->mediaAccMap[mediaId]->releaseDir(dirname);
+ }
+
+
+ // ---------------------------------------------------------------
+ void
+ MediaManager::releasePath(MediaId mediaId,
+ const Pathname & pathname) const
+ {
+ if( !m_impl->hasMediaAcc( mediaId))
+ {
+ ZYPP_THROW(MediaNotOpenException(
+ "Invalid media id " + str::numstring(mediaId)
+ ));
+ }
+
+ m_impl->mediaAccMap[mediaId]->releasePath(pathname);
+ }
+
+ // ---------------------------------------------------------------
+ void
+ MediaManager::dirInfo(MediaId mediaId,
+ std::list<std::string> & retlist,
+ const Pathname & dirname, bool dots) const
+ {
+ if( !m_impl->hasMediaAcc( mediaId))
+ {
+ ZYPP_THROW(MediaNotOpenException(
+ "Invalid media id " + str::numstring(mediaId)
+ ));
+ }
+
+ m_impl->mediaAccMap[mediaId]->dirInfo(retlist, dirname, dots);
+ }
+
+ // ---------------------------------------------------------------
+ void
+ MediaManager::dirInfo(MediaId mediaId,
+ filesystem::DirContent & retlist,
+ const Pathname & dirname, bool dots) const
+ {
+ if( !m_impl->hasMediaAcc( mediaId))
+ {
+ ZYPP_THROW(MediaNotOpenException(
+ "Invalid media id " + str::numstring(mediaId)
+ ));
+ }
+
+ m_impl->mediaAccMap[mediaId]->dirInfo(retlist, dirname, dots);
+ }
//////////////////////////////////////////////////////////////////
} // namespace media
release(MediaId mediaId, bool eject = false);
/**
+ * Disconnect a remote media.
+ *
+ * This is useful for media which e.g. holds open a connection
+ * to a server like FTP. After calling disconnect() the media
+ * object (attach point) is still valid and files are present.
+ *
+ * But after calling disconnect() it's not possible to call
+ * fetch more data using the provideFile() or provideDir()
+ * functions anymore.
+ *
+ * \throws MediaException
+ */
+ void
+ disconnect(MediaId mediaId);
+
+ /**
* Check if media is attached or not.
* \return True if media is attached.
*/
bool
isDesiredMedia(MediaId mediaId, MediaNr mediaNr) const;
+ /**
+ * Return the local directory that corresponds to medias url,
+ * no matter if media isAttached or not. Files requested will
+ * be available at 'localRoot() + filename' or even better
+ * 'localPath( filename )'
+ *
+ * If media is not open an empty pathname is returned.
+ */
+ Pathname
+ localRoot(MediaId mediaId) const;
+
+ /**
+ * Shortcut for 'localRoot() + pathname', but returns an empty
+ * pathname if media is not open.
+ * Files provided will be available at 'localPath(filename)'.
+ */
+ Pathname
+ localPath(MediaId mediaId, const Pathname & pathname) const;
+
public:
/**
* Provide provide file denoted by relative path below of the
bool cached = false,
bool checkonly = false) const;
- /*
- ** FIXME: other from MediaHandler/MediaAccess interface...
- */
+ /**
+ */
+ void
+ provideDir(MediaId mediaId,
+ MediaNr mediaNr,
+ const Pathname & dirname ) const;
+
+ /**
+ */
+ void
+ provideDirTree(MediaId mediaId,
+ MediaNr mediaNr,
+ const Pathname & dirname ) const;
+
+ /**
+ */
+ void
+ releaseFile(MediaId mediaId,
+ const Pathname & filename) const;
+
+ /**
+ */
+ void
+ releaseDir(MediaId mediaId,
+ const Pathname & dirname ) const;
+
+ /**
+ */
+ void
+ releasePath(MediaId mediaId,
+ const Pathname & pathname ) const;
+
+ /**
+ */
+ void dirInfo(MediaId mediaId,
+ std::list<std::string> & retlist,
+ const Pathname & dirname, bool dots = true ) const;
+
+ void dirInfo(MediaId mediaId,
+ filesystem::DirContent & retlist,
+ const Pathname & dirname, bool dots = true ) const;
private:
class Impl;