From 2fc46efee553b1e939ef3979dc6574d56fac5465 Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Thu, 2 Feb 2006 15:28:45 +0000 Subject: [PATCH] - Added dirInfo and other provide and release variants - Added disconnect, localRoot, localPath functions --- zypp/media/MediaManager.cc | 167 ++++++++++++++++++++++++++++++++++++++++++++- zypp/media/MediaManager.h | 79 ++++++++++++++++++++- 2 files changed, 241 insertions(+), 5 deletions(-) diff --git a/zypp/media/MediaManager.cc b/zypp/media/MediaManager.cc index 337846f..ab3a465 100644 --- a/zypp/media/MediaManager.cc +++ b/zypp/media/MediaManager.cc @@ -275,6 +275,21 @@ namespace zypp } // --------------------------------------------------------------- + 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 { @@ -314,6 +329,41 @@ namespace zypp } // --------------------------------------------------------------- + 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, @@ -323,14 +373,127 @@ namespace zypp 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 & 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 diff --git a/zypp/media/MediaManager.h b/zypp/media/MediaManager.h index 49ec47e..ff98b92 100644 --- a/zypp/media/MediaManager.h +++ b/zypp/media/MediaManager.h @@ -138,6 +138,22 @@ namespace zypp 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. */ @@ -152,6 +168,25 @@ namespace zypp 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 @@ -177,9 +212,47 @@ namespace zypp 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 & 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; -- 2.7.4