zypp::media::MediaManager Class Reference

Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees, etc, using Media Access Url's. More...

#include <MediaManager.h>

Inheritance diagram for zypp::media::MediaManager:
[legend]

List of all members.

Public Member Functions

 MediaManager ()
 Creates a MediaManager envelope instance.
 ~MediaManager ()
 Destroys MediaManager envelope instance.
MediaAccessId open (const Url &url, const Pathname &preferred_attach_point="")
 Opens the media access for specified with the url.
void close (MediaAccessId accessId)
 Close the media access with specified id.
bool isOpen (MediaAccessId accessId) const
 Query if the media access is open / exists.
std::string protocol (MediaAccessId accessId) const
 Query the protocol name used by the media access handler.
bool downloads (MediaAccessId accessId) const
 Hint if files are downloaded or not.
Url url (MediaAccessId accessId) const
 Returns the Media Access Url of the media access id.
void addVerifier (MediaAccessId accessId, const MediaVerifierRef &verifier)
 Add verifier implementation for the specified media id.
void delVerifier (MediaAccessId accessId)
 Remove verifier for specified media id.
bool setAttachPrefix (const Pathname &attach_prefix)
 Set or resets the directory name, where the media manager handlers create their temporary attach points (see open() function).
void attach (MediaAccessId accessId)
 Attach the media using the concrete handler (checks all devices).
ZYPP_DEPRECATED void attachDesiredMedia (MediaAccessId accessId)
void release (MediaAccessId accessId, const std::string &ejectDev="")
 Release the attached media and optionally eject.
void releaseAll ()
 Release all attached media.
void disconnect (MediaAccessId accessId)
 Disconnect a remote media.
bool isAttached (MediaAccessId accessId) const
 Check if media is attached or not.
bool isSharedMedia (MediaAccessId accessId) const
 Returns information if media is on a shared physical device or not.
bool isDesiredMedia (MediaAccessId accessId) const
 Ask the registered verifier if the attached media is the desired one or not.
bool isDesiredMedia (MediaAccessId accessId, const MediaVerifierRef &verifier) const
 Ask the specified verifier if the attached media is the desired one or not.
bool isChangeable (MediaAccessId accessId)
 Simple check, based on media's URL scheme, telling whether the it is possible to physically change the media inside its drive, like CDs or DVDs.
Pathname localRoot (MediaAccessId accessId) const
 Return the local directory that corresponds to medias url, no matter if media isAttached or not.
Pathname localPath (MediaAccessId accessId, const Pathname &pathname) const
 Shortcut for 'localRoot() + pathname', but returns an empty pathname if media is not attached.
void provideFile (MediaAccessId accessId, const Pathname &filename) const
 Provide provide file denoted by relative path below of the 'attach point' of the specified media and the path prefix on the media.
void provideDir (MediaAccessId accessId, const Pathname &dirname) const
 FIXME: see MediaAccess class.
void provideDirTree (MediaAccessId accessId, const Pathname &dirname) const
 FIXME: see MediaAccess class.
void releaseFile (MediaAccessId accessId, const Pathname &filename) const
 FIXME: see MediaAccess class.
void releaseDir (MediaAccessId accessId, const Pathname &dirname) const
 FIXME: see MediaAccess class.
void releasePath (MediaAccessId accessId, const Pathname &pathname) const
 FIXME: see MediaAccess class.
void dirInfo (MediaAccessId accessId, std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
 FIXME: see MediaAccess class.
void dirInfo (MediaAccessId accessId, filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const
 FIXME: see MediaAccess class.
bool doesFileExist (MediaAccessId accessId, const Pathname &filename) const
 FIXME: see MediaAccess class.
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 the vector.
bool isUseableAttachPoint (const Pathname &path, bool mtab=true) const
 Check if the specified path is useable as attach point.

Static Public Member Functions

static ZYPP_DEPRECATED bool downloads (const Url &url)
static time_t getMountTableMTime ()
 Get the modification time of the /etc/mtab file.
static std::vector< MountEntrygetMountEntries ()
 Get current mount entries from /etc/mtab file.

Private Member Functions

AttachedMedia getAttachedMedia (MediaAccessId &accessId) const
AttachedMedia findAttachedMedia (const MediaSourceRef &media) const
void forceReleaseShared (const MediaSourceRef &media)

Static Private Attributes

static zypp::RW_pointer
< MediaManager_Impl
m_impl
 Static reference to the implementation (singleton).

Friends

class MediaHandler


Detailed Description

Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees, etc, using Media Access Url's.

Note:
The MediaManager class is just an envelope around an inner singleton like implementation.
That is, you can create as many managers as you want, also temporary in a function call.
But don't declare static MediaManager instances, unless you want to force (mutex) initialization order problems!

Media Access Url

The MediaManager uses several media access handlers (backends), that can be specified by a Media Access URL in its open() method.

All URL's may contain following query parameters, that are reserved by the Source classes and unused/ignored by the media manager:

Currently, following access handlers (backends) are implemented:

MediaCD - CD/DVD drives (cd, dvd)

The access handler for media on CD / DVD drives.

MediaDISK - HD disk volumes (hd)

The access handler for media on a disk volume (partition).

MediaDIR - Local directory tree (dir, file)

The access handler to media stored in a local directory tree.

MediaISO - Loopback ISO images (iso)

The access handler for media in a ISO image (loopback mount).

MediaNFS - NFS directory tree (nfs)

The access handler for media on NFS exported directory tree.

MediaCIFS - CIFS/SMB directory tree (cifs, smb)

The access handler for media in a CIFS/SMB shared directory tree.

MediaCurl - FTP/HTTP directory tree (ftp, http, https)

The access handler to media directory tree on a ftp/http server.

Proxy settings: If no proxy settings are present in tha URLs query parameters, the media handler reads the system wide proxy settings from the /etc/sysconfig/proxy file. If a proxy setting was present, but the proxy password not, it attempts to read the proxy-user variable from the ~/.curlrc (/root/.curlrc) file.
If no proxy setting was present, then libzypp does not pass any proxy settings to curl, but curl fallbacks to use the content of the http_proxy, ftp_proxy, etc environment variables.

Definition at line 438 of file MediaManager.h.


Constructor & Destructor Documentation

zypp::media::MediaManager::MediaManager (  ) 

Creates a MediaManager envelope instance.

In the case, that the inner implementation is not already allocated, and the MediaManager constructor was unable to allocate it, a std::bad_alloc exception is thrown.

All further instances increase the use counter only.

Exceptions:
std::bad_alloc 

Definition at line 248 of file MediaManager.cc.

References m_impl, and zypp::RW_pointer< _D, _Traits >::reset().

zypp::media::MediaManager::~MediaManager (  ) 

Destroys MediaManager envelope instance.

Decreases the use counter of the inner implementation.

Definition at line 258 of file MediaManager.cc.


Member Function Documentation

MediaAccessId zypp::media::MediaManager::open ( const Url url,
const Pathname &  preferred_attach_point = "" 
)

Opens the media access for specified with the url.

If the preferred_attach_point parameter does not point to a usable attach point directory, the media manager automatically creates a temporary attach point in a default directory. This default directory can be changed using setAttachPrefix() function.

Remember to close() each id you've opened and not need any more. It is like a new and delete!

Parameters:
url The Media Access Url.
preferred_attach_point The preferred, already existing directory, where the media should be attached.
Returns:
a new media access id.
Exceptions:
std::bad_alloc 
MediaException 

Definition at line 264 of file MediaManager.cc.

References zypp::Url::asString(), DBG, handler, m_impl, and verifier.

Referenced by zypp::MediaSetAccess::getMediaAccessId(), zypp::media::MediaISO::MediaISO(), zypp::productsInMedia(), and zypp::repo::RIMServiceRepos::RIMServiceRepos().

void zypp::media::MediaManager::close ( MediaAccessId  accessId  ) 

Close the media access with specified id.

Parameters:
accessId The media access id to close.

Definition at line 286 of file MediaManager.cc.

References DBG, m_impl, and ZYPP_THROW.

Referenced by zypp::MediaSetAccess::provide(), zypp::repo::RIMServiceRepos::RIMServiceRepos(), and zypp::media::MediaISO::~MediaISO().

bool zypp::media::MediaManager::isOpen ( MediaAccessId  accessId  )  const

Query if the media access is open / exists.

Parameters:
accessId The media access id to query.
Returns:
true, if access id is known and open.

Definition at line 322 of file MediaManager.cc.

References m_impl.

Referenced by zypp::media::MediaISO::~MediaISO().

std::string zypp::media::MediaManager::protocol ( MediaAccessId  accessId  )  const

Query the protocol name used by the media access handler.

Similar to url().getScheme().

Parameters:
accessId The media access id to query.
Returns:
The protocol name used by the media access handler, otherwise 'unknown'.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 333 of file MediaManager.cc.

References m_impl.

bool zypp::media::MediaManager::downloads ( MediaAccessId  accessId  )  const

Hint if files are downloaded or not.

Parameters:
accessId The media access id to query.
Returns:
True, if provideFile downloads files.

Definition at line 344 of file MediaManager.cc.

References m_impl.

static ZYPP_DEPRECATED bool zypp::media::MediaManager::downloads ( const Url url  )  [inline, static]

Url zypp::media::MediaManager::url ( MediaAccessId  accessId  )  const

Returns the Media Access Url of the media access id.

Parameters:
accessId The media access id to query.
Returns:
The Media Access Url used by the media access id.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 355 of file MediaManager.cc.

References m_impl.

Referenced by isChangeable().

void zypp::media::MediaManager::addVerifier ( MediaAccessId  accessId,
const MediaVerifierRef verifier 
)

Add verifier implementation for the specified media id.

By default, the NoVerifier is used.

Parameters:
accessId A media access id.
verifier The new verifier.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 366 of file MediaManager.cc.

References DBG, m_impl, and ZYPP_THROW.

Referenced by zypp::MediaSetAccess::getMediaAccessId(), and zypp::MediaSetAccess::setVerifier().

void zypp::media::MediaManager::delVerifier ( MediaAccessId  accessId  ) 

Remove verifier for specified media id.

It resets the verifier to NoVerifier.

Parameters:
accessId A media access id.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 385 of file MediaManager.cc.

References DBG, m_impl, and verifier.

Referenced by zypp::MediaSetAccess::getMediaAccessId().

bool zypp::media::MediaManager::setAttachPrefix ( const Pathname &  attach_prefix  ) 

Set or resets the directory name, where the media manager handlers create their temporary attach points (see open() function).

It has effect to newly created temporary attach points only.

Parameters:
attach_prefix The new prefix for temporary attach points, or empty pathname to reset to defaults.
Returns:
True on success, false if the attach_prefix parameters contains a path name, that does not point to a writable directory.

Definition at line 401 of file MediaManager.cc.

void zypp::media::MediaManager::attach ( MediaAccessId  accessId  ) 

Attach the media using the concrete handler (checks all devices).

Remember to release() or close() each id you've attached and not need any more. Attach is like an open of a file!

Parameters:
accessId A media access id.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 409 of file MediaManager.cc.

References DBG, m_impl, MIL, ZYPP_CAUGHT, and ZYPP_RETHROW.

Referenced by attachDesiredMedia(), zypp::media::MediaISO::attachTo(), zypp::MediaSetAccess::dirInfo(), zypp::productsInMedia(), zypp::MediaSetAccess::provide(), and zypp::repo::RIMServiceRepos::RIMServiceRepos().

ZYPP_DEPRECATED void zypp::media::MediaManager::attachDesiredMedia ( MediaAccessId  accessId  )  [inline]

Deprecated:
Simply use attach.

Definition at line 586 of file MediaManager.h.

References attach().

void zypp::media::MediaManager::release ( MediaAccessId  accessId,
const std::string &  ejectDev = "" 
)

Release the attached media and optionally eject.

If the ejectDev parameter is not empty all other access id's are released and the specified drive (CD/DVD drive) is ejected.

Parameters:
accessId A media access id.
ejectDev Device to eject. None if empty.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 479 of file MediaManager.cc.

References DBG, m_impl, and ZYPP_CAUGHT.

Referenced by zypp::media::MediaISO::attachTo(), zypp::productsInMedia(), zypp::MediaSetAccess::provide(), zypp::MediaSetAccess::release(), zypp::media::MediaISO::releaseFrom(), and zypp::repo::RIMServiceRepos::RIMServiceRepos().

void zypp::media::MediaManager::releaseAll (  ) 

Release all attached media.

Definition at line 523 of file MediaManager.cc.

References DBG, ERR, m_impl, MIL, and ZYPP_CAUGHT.

Referenced by zypp::MediaSetAccess::provide().

void zypp::media::MediaManager::disconnect ( MediaAccessId  accessId  ) 

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.

Parameters:
accessId A media access id.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 560 of file MediaManager.cc.

References m_impl.

bool zypp::media::MediaManager::isAttached ( MediaAccessId  accessId  )  const

Check if media is attached or not.

Parameters:
accessId A media access id.
Returns:
True if media is attached.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 571 of file MediaManager.cc.

References m_impl.

Referenced by zypp::MediaSetAccess::dirInfo(), zypp::MediaSetAccess::provide(), and zypp::MediaSetAccess::releaseFile().

bool zypp::media::MediaManager::isSharedMedia ( MediaAccessId  accessId  )  const

Returns information if media is on a shared physical device or not.

Parameters:
accessId A media access id.
Returns:
True if it is shared, false if not.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 581 of file MediaManager.cc.

References m_impl.

bool zypp::media::MediaManager::isDesiredMedia ( MediaAccessId  accessId  )  const

Ask the registered verifier if the attached media is the desired one or not.

Parameters:
accessId A media access id.
Returns:
True if media is attached and desired according to the actual verifier.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 592 of file MediaManager.cc.

References DBG, m_impl, and ZYPP_CAUGHT.

bool zypp::media::MediaManager::isDesiredMedia ( MediaAccessId  accessId,
const MediaVerifierRef verifier 
) const

Ask the specified verifier if the attached media is the desired one or not.

Parameters:
accessId A media access id.
verifier A verifier to use.
Returns:
True if media is attached and desired according to the specified verifier.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 621 of file MediaManager.cc.

References DBG, desired, m_impl, ZYPP_CAUGHT, and ZYPP_THROW.

bool zypp::media::MediaManager::isChangeable ( MediaAccessId  accessId  ) 

Simple check, based on media's URL scheme, telling whether the it is possible to physically change the media inside its drive, like CDs or DVDs.

Useful to decide whether to request media change from user or not.

Parameters:
accessId The media access id.
Returns:
false if the media is not changeable, true otherwise.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 652 of file MediaManager.cc.

References zypp::Url::getScheme(), and url().

Pathname zypp::media::MediaManager::localRoot ( MediaAccessId  accessId  )  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 )'

Parameters:
accessId A media access id.
Returns:
The directory name pointing to the media root in local filesystem or an empty pathname if the media is not attached.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 659 of file MediaManager.cc.

References m_impl.

Pathname zypp::media::MediaManager::localPath ( MediaAccessId  accessId,
const Pathname &  pathname 
) const

Shortcut for 'localRoot() + pathname', but returns an empty pathname if media is not attached.

Files provided will be available at 'localPath(filename)'.

Parameters:
accessId A media access id.
pathname A path name relative to the localRoot().
Returns:
The directory name in local filesystem pointing to the desired relative pathname on the media or an empty pathname if the media is not attached.
Exceptions:
MediaNotOpenException for invalid access id.

Definition at line 672 of file MediaManager.cc.

References m_impl.

Referenced by zypp::media::MediaISO::attachTo(), zypp::ProvideDirOperation::operator()(), zypp::ProvideDirTreeOperation::operator()(), zypp::ProvideFileOperation::operator()(), zypp::productsInMedia(), and zypp::repo::RIMServiceRepos::RIMServiceRepos().

void zypp::media::MediaManager::provideFile ( MediaAccessId  accessId,
const Pathname &  filename 
) const

Provide provide file denoted by relative path below of the 'attach point' of the specified media and the path prefix on the media.

Parameters:
accessId The media access id to use.
filename The filename to provide, relative to localRoot().
Exceptions:
MediaNotOpenException in case of invalid access id.
MediaNotAttachedException in case, that the media is not attached.
MediaNotDesiredException in case, that the media verification failed.
MediaNotAFileException in case, that the requested filename is not a file.
MediaFileNotFoundException in case, that the requested filenamedoes not exists.
MediaWriteException in case, that the file can't be copied from from remote source.
MediaSystemException in case a system operation fails.
MediaException derived exception, depending on the url (handler).

Definition at line 686 of file MediaManager.cc.

References m_impl.

Referenced by zypp::media::MediaISO::attachTo(), zypp::ProvideFileOperation::operator()(), zypp::productsInMedia(), and zypp::repo::RIMServiceRepos::RIMServiceRepos().

void zypp::media::MediaManager::provideDir ( MediaAccessId  accessId,
const Pathname &  dirname 
) const

FIXME: see MediaAccess class.

Definition at line 700 of file MediaManager.cc.

References m_impl.

Referenced by zypp::ProvideDirOperation::operator()().

void zypp::media::MediaManager::provideDirTree ( MediaAccessId  accessId,
const Pathname &  dirname 
) const

FIXME: see MediaAccess class.

Definition at line 714 of file MediaManager.cc.

References m_impl.

Referenced by zypp::ProvideDirTreeOperation::operator()().

void zypp::media::MediaManager::releaseFile ( MediaAccessId  accessId,
const Pathname &  filename 
) const

FIXME: see MediaAccess class.

Definition at line 728 of file MediaManager.cc.

References m_impl.

Referenced by zypp::MediaSetAccess::releaseFile().

void zypp::media::MediaManager::releaseDir ( MediaAccessId  accessId,
const Pathname &  dirname 
) const

FIXME: see MediaAccess class.

Definition at line 742 of file MediaManager.cc.

References m_impl.

void zypp::media::MediaManager::releasePath ( MediaAccessId  accessId,
const Pathname &  pathname 
) const

FIXME: see MediaAccess class.

Definition at line 757 of file MediaManager.cc.

References m_impl.

void zypp::media::MediaManager::dirInfo ( MediaAccessId  accessId,
std::list< std::string > &  retlist,
const Pathname &  dirname,
bool  dots = true 
) const

FIXME: see MediaAccess class.

Definition at line 771 of file MediaManager.cc.

References m_impl.

Referenced by zypp::MediaSetAccess::dirInfo().

void zypp::media::MediaManager::dirInfo ( MediaAccessId  accessId,
filesystem::DirContent retlist,
const Pathname &  dirname,
bool  dots = true 
) const

FIXME: see MediaAccess class.

Definition at line 788 of file MediaManager.cc.

References m_impl.

bool zypp::media::MediaManager::doesFileExist ( MediaAccessId  accessId,
const Pathname &  filename 
) const

FIXME: see MediaAccess class.

Definition at line 805 of file MediaManager.cc.

References m_impl.

Referenced by zypp::ProvideFileExistenceOperation::operator()().

void zypp::media::MediaManager::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 the vector.

The contents of the vector are the device names (/dev/cdrom and such).

Parameters:
accessId Medium id.
devices vector to load with the device names
index index of the currently used device in the devices vector

Definition at line 818 of file MediaManager.cc.

References m_impl.

Referenced by zypp::MediaSetAccess::provide().

time_t zypp::media::MediaManager::getMountTableMTime (  )  [static]

Get the modification time of the /etc/mtab file.

Returns:
Modification time of the /etc/mtab file.

Definition at line 830 of file MediaManager.cc.

Referenced by zypp::media::MediaHandler::checkAttached().

MountEntries zypp::media::MediaManager::getMountEntries (  )  [static]

Get current mount entries from /etc/mtab file.

Returns:
Current mount entries from /etc/mtab file.

Definition at line 839 of file MediaManager.cc.

Referenced by zypp::media::MediaDISK::attachTo(), zypp::media::MediaCD::attachTo(), zypp::media::MediaHandler::checkAttached(), and zypp::media::MediaHandler::forceRelaseAllMedia().

bool zypp::media::MediaManager::isUseableAttachPoint ( const Pathname &  path,
bool  mtab = true 
) const

Check if the specified path is useable as attach point.

Parameters:
path The attach point to check.
mtab Whether to check against the mtab, too.
Returns:
True, if it is a directory and there are no another attach points bellow of it.

Definition at line 848 of file MediaManager.cc.

References zypp::media::AttachedMedia::attachPoint, m_impl, and zypp::media::AttachedMedia::mediaSource.

Referenced by zypp::media::MediaHandler::isUseableAttachPoint().

AttachedMedia zypp::media::MediaManager::getAttachedMedia ( MediaAccessId accessId  )  const [private]

Definition at line 919 of file MediaManager.cc.

References m_impl.

Referenced by zypp::media::MediaHandler::dependsOnParent().

AttachedMedia zypp::media::MediaManager::findAttachedMedia ( const MediaSourceRef media  )  const [private]

Definition at line 930 of file MediaManager.cc.

References m_impl, and zypp::media::AttachedMedia::mediaSource.

void zypp::media::MediaManager::forceReleaseShared ( const MediaSourceRef media  )  [private]

Definition at line 952 of file MediaManager.cc.

References m_impl, and zypp::media::AttachedMedia::mediaSource.

Referenced by zypp::media::MediaHandler::release().


Friends And Related Function Documentation

friend class MediaHandler [friend]

Definition at line 842 of file MediaManager.h.


Member Data Documentation


The documentation for this class was generated from the following files:

doxygen