libzypp 17.36.1
|
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees, etc, using Media Access Url's. More...
#include <zypp/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:
Currently, following access handlers (backends) are implemented:
The access handler for media on CD / DVD drives.
The access handler for media on a disk volume (partition).
The access handler to media stored in a local directory tree.
The access handler for media in a ISO image (loopback mount).
The access handler for media on NFS exported directory tree.
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.
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.
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.
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 301 of file MediaManager.cc.
zypp::media::MediaManager::~MediaManager | ( | ) |
Destroys MediaManager envelope instance.
Decreases the use counter of the inner implementation.
Definition at line 310 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 316 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 334 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 368 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 376 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 385 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 394 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 403 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 420 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 434 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 440 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 509 of file MediaManager.cc.
void zypp::media::MediaManager::releaseAll | ( | ) |
Release all attached media.
Definition at line 552 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 589 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 598 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 606 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 615 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 642 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. |
MediaNotOpenException | for invalid access id. |
Definition at line 671 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 678 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 689 of file MediaManager.cc.
void zypp::media::MediaManager::provideFile | ( | MediaAccessId | accessId, |
const Pathname & | filename, | ||
const ByteCount & | expectedFileSize ) const |
Definition at line 700 of file MediaManager.cc.
void zypp::media::MediaManager::provideFile | ( | MediaAccessId | accessId, |
const Pathname & | filename ) const |
Definition at line 715 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 726 of file MediaManager.cc.
void zypp::media::MediaManager::provideDir | ( | MediaAccessId | accessId, |
const Pathname & | dirname ) const |
FIXME: see MediaAccess class.
Definition at line 758 of file MediaManager.cc.
void zypp::media::MediaManager::provideDirTree | ( | MediaAccessId | accessId, |
const Pathname & | dirname ) const |
FIXME: see MediaAccess class.
Definition at line 770 of file MediaManager.cc.
void zypp::media::MediaManager::releaseFile | ( | MediaAccessId | accessId, |
const Pathname & | filename ) const |
FIXME: see MediaAccess class.
Definition at line 782 of file MediaManager.cc.
void zypp::media::MediaManager::releaseDir | ( | MediaAccessId | accessId, |
const Pathname & | dirname ) const |
FIXME: see MediaAccess class.
Definition at line 794 of file MediaManager.cc.
void zypp::media::MediaManager::releasePath | ( | MediaAccessId | accessId, |
const Pathname & | pathname ) const |
FIXME: see MediaAccess class.
Definition at line 807 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 819 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 834 of file MediaManager.cc.
bool zypp::media::MediaManager::doesFileExist | ( | MediaAccessId | accessId, |
const Pathname & | filename ) const |
FIXME: see MediaAccess class.
Definition at line 849 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 861 of file MediaManager.cc.
void zypp::media::MediaManager::setDeltafile | ( | MediaAccessId | accessId, |
const Pathname & | filename ) const |
Definition at line 737 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 747 of file MediaManager.cc.
|
static |
Get the modification time of the /etc/mtab file.
Definition at line 872 of file MediaManager.cc.
|
static |
Get current mount entries from /etc/mtab file.
Definition at line 880 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 887 of file MediaManager.cc.
|
private |
Definition at line 956 of file MediaManager.cc.
|
private |
Definition at line 965 of file MediaManager.cc.
|
private |
Definition at line 985 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.