libzypp 17.31.23
|
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees, etc, using Media Access Url's. More...
#include <media/MediaManager.h>
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). | |
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. | |
ZYPP_DEPRECATED void | provideFile (MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const |
ZYPP_DEPRECATED void | provideFile (MediaAccessId accessId, const Pathname &filename) const |
void | provideFile (MediaAccessId accessId, const OnMediaLocation &file) 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. | |
ZYPP_DEPRECATED void | setDeltafile (MediaAccessId accessId, const Pathname &filename) const |
void | precacheFiles (MediaAccessId accessId, const std::vector< OnMediaLocation > &files) |
Tries to fetch the given files and precaches them. | |
bool | isUseableAttachPoint (const Pathname &path, bool mtab=true) const |
Check if the specified path is useable as attach point. | |
Static Public Member Functions | |
static time_t | getMountTableMTime () |
Get the modification time of the /etc/mtab file. | |
static std::vector< MountEntry > | getMountEntries () |
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 |
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees, etc, using Media Access Url's.
The MediaManager uses several media access handlers (backends), that can be specified by a Media Access URL in its open() method.
All URLs may contain following query parameters, that are reserved by the Source classes and unused/ignored by the media manager:
alias
: A source specific media alias string.Currently, following access handlers (backends) are implemented:
The access handler for media on CD / DVD drives.
devices
: Optional parameter, containing a comma separated list of block device names to use, e.g.: "/dev/sr0,/dev/sr1". The access handler for media on a disk volume (partition).
device
: Mandatory parameter specifying the name of the block device of the partition to mount.filesystem
: The name of the filesystem. Defaults to "auto".The access handler to media stored in a local directory tree.
The access handler for media in a ISO image (loopback mount).
iso
: Mandatory parameter specifying the name of the iso file.url
: Optional parameter specifying the URL to the directory containing the iso file.mnt
: Optional parameter specifying the prefered attach point for the source media url.filesystem
: Optional name of the filesystem used in the iso file. Defaults to "auto".The access handler for media on NFS exported directory tree.
mountoptions
: The mount options separated by comma ','. Default is the "ro" option.type=nfs4
: Whether to mount as nfs4. This is the default for scheme nfs4.Authority: The authority component has to provide a hostname. Username, password and port are currently ignored.
The access handler for media in a CIFS/SMB shared directory tree.
mountoptions
: The mount options separated by a comma ','. Default are the "ro" and "guest" options. Specify "noguest" to turn off "guest". This is necessary if Samba is configured to reject guest connections.workgroup
or domain
: The name of the workgroup.username
: Alternative username to username in URL authority.password
: Alternative password to password in URL authority.user
: Alternative username (cifs specific variant)pass
: Alternative password (cifs specific variant)The access handler to media directory tree on a ftp/http server.
cookies
: Turn off using cookies by setting it to "0" (or false, no, off).proxy
: A proxy hostname or hostname and port separated by ':'. Setting the hostname to 'none' explicitly disables the use of a proxy even if configured in /etc/sysconfig/proxy or the environment.proxyport
: Alternative way to provide the proxy port.proxyuser
: The proxy username.proxypass
: The proxy password.ssl_capath
: The absolute CA directory to use, default is /etc/ssl/certs.ssl_verify
: Flag to modify the ssl verify behaviour. Valid values are: 'yes', 'no' and a comma separated list of 'host' and 'peer' flags.ssl_capath
.ssl_clientcert
Path to the ssl client certificate for authentication to a repo (CURLOPT_SSLCERT).ssl_clientkey
Path to the ssl client key for authentication to a repo (CURLOPT_SSLKEY).timeout
: Transfer timeout in seconds between 0 and 3600, 0 disables the timeout, default timeout is 180 seconds.auth
: A comma separated list of http authentication method names to use: 'basic', 'digest', 'ntlm', 'negotiate', 'spnego', 'gssnego'. Note, that this list depends on the list of methods supported by the curl library.mediahandler
: Set the mediahandler for this url Valid values are: 'curl', 'multicurl'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.
Media access is delegated to a script located in the libzypp media plugin directory. The URLs query options are translated into commandline arguments passed to the script.
(option,value)
pairs are stored in a hash.'– value'
and passed as final option.'c[=[value]]'
ist passed as '-c [value]'
'word[=[value]]'
ist passed as '–word [value]'
'[=value]'
ist passed as last args as '– [value]'
script<->libzypp
communication:Definition at line 453 of file MediaManager.h.
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.
std::bad_alloc |
Definition at line 293 of file MediaManager.cc.
zypp::media::MediaManager::~MediaManager | ( | ) |
Destroys MediaManager envelope instance.
Decreases the use counter of the inner implementation.
Definition at line 302 of file MediaManager.cc.
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!
url | The Media Access Url. |
preferred_attach_point | The preferred, already existing directory, where the media should be attached. |
std::bad_alloc | |
MediaException |
Definition at line 308 of file MediaManager.cc.
void zypp::media::MediaManager::close | ( | MediaAccessId | accessId | ) |
Close the media access with specified id.
accessId | The media access id to close. |
Definition at line 326 of file MediaManager.cc.
bool zypp::media::MediaManager::isOpen | ( | MediaAccessId | accessId | ) | const |
Query if the media access is open / exists.
accessId | The media access id to query. |
Definition at line 360 of file MediaManager.cc.
std::string zypp::media::MediaManager::protocol | ( | MediaAccessId | accessId | ) | const |
Query the protocol name used by the media access handler.
Similar to url().getScheme().
accessId | The media access id to query. |
MediaNotOpenException | for invalid access id. |
Definition at line 368 of file MediaManager.cc.
bool zypp::media::MediaManager::downloads | ( | MediaAccessId | accessId | ) | const |
Hint if files are downloaded or not.
accessId | The media access id to query. |
Definition at line 377 of file MediaManager.cc.
Url zypp::media::MediaManager::url | ( | MediaAccessId | accessId | ) | const |
Returns the Media Access Url of the media access id.
accessId | The media access id to query. |
MediaNotOpenException | for invalid access id. |
Definition at line 386 of file MediaManager.cc.
void zypp::media::MediaManager::addVerifier | ( | MediaAccessId | accessId, |
const MediaVerifierRef & | verifier | ||
) |
Add verifier implementation for the specified media id.
By default, the NoVerifier is used.
accessId | A media access id. |
verifier | The new verifier. |
MediaNotOpenException | for invalid access id. |
Definition at line 395 of file MediaManager.cc.
void zypp::media::MediaManager::delVerifier | ( | MediaAccessId | accessId | ) |
Remove verifier for specified media id.
It resets the verifier to NoVerifier.
accessId | A media access id. |
MediaNotOpenException | for invalid access id. |
Definition at line 412 of file MediaManager.cc.
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.
attach_prefix | The new prefix for temporary attach points, or empty pathname to reset to defaults. |
attach_prefix
parameters contains a path name, that does not point to a writable directory. Definition at line 426 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!
accessId | A media access id. |
MediaNotOpenException | for invalid access id. |
Definition at line 432 of file MediaManager.cc.
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.
accessId | A media access id. |
ejectDev | Device to eject. None if empty. |
MediaNotOpenException | for invalid access id. |
Definition at line 501 of file MediaManager.cc.
void zypp::media::MediaManager::releaseAll | ( | ) |
Release all attached media.
Definition at line 544 of file MediaManager.cc.
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.
accessId | A media access id. |
MediaNotOpenException | for invalid access id. |
Definition at line 581 of file MediaManager.cc.
bool zypp::media::MediaManager::isAttached | ( | MediaAccessId | accessId | ) | const |
Check if media is attached or not.
accessId | A media access id. |
MediaNotOpenException | for invalid access id. |
Definition at line 590 of file MediaManager.cc.
bool zypp::media::MediaManager::isSharedMedia | ( | MediaAccessId | accessId | ) | const |
Returns information if media is on a shared physical device or not.
accessId | A media access id. |
MediaNotOpenException | for invalid access id. |
Definition at line 598 of file MediaManager.cc.
bool zypp::media::MediaManager::isDesiredMedia | ( | MediaAccessId | accessId | ) | const |
Ask the registered verifier if the attached media is the desired one or not.
accessId | A media access id. |
MediaNotOpenException | for invalid access id. |
Definition at line 607 of file MediaManager.cc.
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.
accessId | A media access id. |
verifier | A verifier to use. |
MediaNotOpenException | for invalid access id. |
Definition at line 634 of file MediaManager.cc.
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.
accessId | The media access id. |
false
if the media is not changeable, true
otherwise. MediaNotOpenException | for invalid access id. |
Definition at line 663 of file MediaManager.cc.
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 )'
accessId | A media access id. |
MediaNotOpenException | for invalid access id. |
Definition at line 670 of file MediaManager.cc.
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)'.
accessId | A media access id. |
pathname | A path name relative to the localRoot(). |
MediaNotOpenException | for invalid access id. |
Definition at line 681 of file MediaManager.cc.
void zypp::media::MediaManager::provideFile | ( | MediaAccessId | accessId, |
const Pathname & | filename, | ||
const ByteCount & | expectedFileSize | ||
) | const |
Definition at line 692 of file MediaManager.cc.
void zypp::media::MediaManager::provideFile | ( | MediaAccessId | accessId, |
const Pathname & | filename | ||
) | const |
Definition at line 707 of file MediaManager.cc.
void zypp::media::MediaManager::provideFile | ( | MediaAccessId | accessId, |
const OnMediaLocation & | file | ||
) | const |
Provide provide file denoted by relative path below of the 'attach point' of the specified media and the path prefix on the media.
accessId | The media access id to use. |
file | The OnMediaLocation specifiying the file to download |
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 718 of file MediaManager.cc.
void zypp::media::MediaManager::provideDir | ( | MediaAccessId | accessId, |
const Pathname & | dirname | ||
) | const |
FIXME: see MediaAccess class.
Definition at line 750 of file MediaManager.cc.
void zypp::media::MediaManager::provideDirTree | ( | MediaAccessId | accessId, |
const Pathname & | dirname | ||
) | const |
FIXME: see MediaAccess class.
Definition at line 762 of file MediaManager.cc.
void zypp::media::MediaManager::releaseFile | ( | MediaAccessId | accessId, |
const Pathname & | filename | ||
) | const |
FIXME: see MediaAccess class.
Definition at line 774 of file MediaManager.cc.
void zypp::media::MediaManager::releaseDir | ( | MediaAccessId | accessId, |
const Pathname & | dirname | ||
) | const |
FIXME: see MediaAccess class.
Definition at line 786 of file MediaManager.cc.
void zypp::media::MediaManager::releasePath | ( | MediaAccessId | accessId, |
const Pathname & | pathname | ||
) | const |
FIXME: see MediaAccess class.
Definition at line 799 of file MediaManager.cc.
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 811 of file MediaManager.cc.
void zypp::media::MediaManager::dirInfo | ( | MediaAccessId | accessId, |
filesystem::DirContent & | retlist, | ||
const Pathname & | dirname, | ||
bool | dots = true |
||
) | const |
FIXME: see MediaAccess class.
Definition at line 826 of file MediaManager.cc.
bool zypp::media::MediaManager::doesFileExist | ( | MediaAccessId | accessId, |
const Pathname & | filename | ||
) | const |
FIXME: see MediaAccess class.
Definition at line 841 of file MediaManager.cc.
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).
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 853 of file MediaManager.cc.
void zypp::media::MediaManager::setDeltafile | ( | MediaAccessId | accessId, |
const Pathname & | filename | ||
) | const |
Definition at line 729 of file MediaManager.cc.
void zypp::media::MediaManager::precacheFiles | ( | MediaAccessId | accessId, |
const std::vector< OnMediaLocation > & | files | ||
) |
Tries to fetch the given files and precaches them.
Those files need to be queried using provideFile and can be read from the cache directly. The implementation is not allowed to block but needs to use seperate means to download the files concurrently. A backend can choose to completely ignore this functionaly, the default implementation does nothing.
accessId | Medium id. |
files | List of files that should be precached |
Definition at line 739 of file MediaManager.cc.
|
static |
Get the modification time of the /etc/mtab file.
Definition at line 864 of file MediaManager.cc.
|
static |
Get current mount entries from /etc/mtab file.
Definition at line 872 of file MediaManager.cc.
bool zypp::media::MediaManager::isUseableAttachPoint | ( | const Pathname & | path, |
bool | mtab = true |
||
) | const |
Check if the specified path
is useable as attach point.
path | The attach point to check. |
mtab | Whether to check against the mtab, too. |
Definition at line 879 of file MediaManager.cc.
|
private |
Definition at line 948 of file MediaManager.cc.
|
private |
Definition at line 957 of file MediaManager.cc.
|
private |
Definition at line 977 of file MediaManager.cc.
|
friend |
Definition at line 884 of file MediaManager.h.
|
staticprivate |
Static reference to the implementation (singleton).
Definition at line 925 of file MediaManager.h.