libzypp  17.14.0
zypp::media::MediaAccess Class Reference

Handle access to a medium. More...

#include <MediaAccess.h>

Inheritance diagram for zypp::media::MediaAccess:

Classes

class  FileProvider
 Helper class that provides file on construction and cleans up on destruction. More...
 

Public Types

typedef intrusive_ptr< MediaAccessPtr
 
typedef intrusive_ptr< const MediaAccessconstPtr
 

Public Member Functions

 MediaAccess ()
 constructor More...
 
void open (const Url &url, const Pathname &preferred_attach_point="")
 open url. More...
 
bool isOpen () const
 True if media is open. More...
 
bool downloads () const
 Hint if files are downloaded or not. More...
 
std::string protocol () const
 Used Protocol if media is opened, otherwise 'unknown'. More...
 
Url url () const
 Url if media is opened, otherwise empty. More...
 
void close ()
 close url More...
 
void attach (bool next=false)
 Use concrete handler to attach the media. More...
 
bool isAttached () const
 True if media is attached. More...
 
bool hasMoreDevices () const
 
virtual void getDetectedDevices (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. More...
 
Pathname localRoot () const
 Return the local directory that corresponds to medias url, no matter if media isAttached or not. More...
 
Pathname localPath (const Pathname &pathname) const
 Short for 'localRoot() + pathname', but returns an empty pathname if media is not open. More...
 
void disconnect ()
 Use concrete handler to disconnect the media. More...
 
void release (const std::string &ejectDev="")
 Use concrete handler to release the media. More...
 
void provideFile (const Pathname &filename, const ByteCount &expectedFileSize) const
 Use concrete handler to provide file denoted by path below 'attach point'. More...
 
void releaseFile (const Pathname &filename) const
 Remove filename below attach point IFF handler downloads files to the local filesystem. More...
 
void provideDir (const Pathname &dirname) const
 Use concrete handler to provide directory denoted by path below 'attach point' (not recursive!). More...
 
void provideDirTree (const Pathname &dirname) const
 Use concrete handler to provide directory tree denoted by path below 'attach point' (recursive!!). More...
 
void releaseDir (const Pathname &dirname) const
 Remove directory tree below attach point IFF handler downloads files to the local filesystem. More...
 
void releasePath (const Pathname &pathname) const
 Remove pathname below attach point IFF handler downloads files to the local filesystem. More...
 
void setDeltafile (const Pathname &filename) const
 set a deltafile to be used in the next download More...
 
void dirInfo (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
 Return content of directory on media via retlist. More...
 
void dirInfo (filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const
 Basically the same as dirInfo above. More...
 
bool doesFileExist (const Pathname &filename) const
 check if a file exists More...
 
virtual ~MediaAccess ()
 Destructor. More...
 
virtual std::ostream & dumpOn (std::ostream &str) const
 Overload to realize std::ostream & operator<<. More...
 
void getFile (const Url &from, const Pathname &to)
 Get file from location at specified by URL and copy it to destination. More...
 
- Public Member Functions inherited from zypp::base::ReferenceCounted
 ReferenceCounted ()
 Default ctor. More...
 
 ReferenceCounted (const ReferenceCounted &rhs)
 Copy ctor. More...
 
virtual ~ReferenceCounted ()
 Dtor. More...
 
ReferenceCountedoperator= (const ReferenceCounted &)
 Assignment. More...
 
unsigned refCount () const
 Return reference counter value. More...
 
void ref () const
 Add a reference. More...
 
void unref () const
 Release a reference. More...
 

Private Member Functions

AttachedMedia attachedMedia () const
 
bool isSharedMedia () const
 
void resetParentId ()
 
bool dependsOnParent () const
 
bool dependsOnParent (MediaAccessId parentId, bool exactIdMatch) const
 

Private Attributes

MediaHandler_handler
 handler for 'physical' media == 0 if not open More...
 

Static Private Attributes

static const Pathname _noPath
 

Friends

class MediaManager
 
class MediaManager_Impl
 

Additional Inherited Members

- Static Public Member Functions inherited from zypp::base::ReferenceCounted
static void add_ref (const ReferenceCounted *ptr_r)
 Called by zypp::intrusive_ptr to add a reference. More...
 
static void release (const ReferenceCounted *ptr_r)
 Called by zypp::intrusive_ptr to add a reference. More...
 
- Protected Member Functions inherited from zypp::base::ReferenceCounted
virtual void ref_to (unsigned) const
 Trigger derived classes after refCount was increased. More...
 
virtual void unref_to (unsigned) const
 Trigger derived classes after refCount was decreased. More...
 

Detailed Description

Handle access to a medium.

The concrete MediaHandler for a certain url is created on open and deleted on @close.

The inteface here basically checks whether the handler exists, then forwards the request to MediaHandler.

Definition at line 50 of file MediaAccess.h.

Member Typedef Documentation

◆ Ptr

◆ constPtr

Definition at line 54 of file MediaAccess.h.

Constructor & Destructor Documentation

◆ MediaAccess()

zypp::media::MediaAccess::MediaAccess ( )

constructor

Definition at line 53 of file MediaAccess.cc.

◆ ~MediaAccess()

zypp::media::MediaAccess::~MediaAccess ( )
virtual

Destructor.

Definition at line 59 of file MediaAccess.cc.

Member Function Documentation

◆ attachedMedia()

AttachedMedia zypp::media::MediaAccess::attachedMedia ( ) const
private

Definition at line 69 of file MediaAccess.cc.

◆ isSharedMedia()

bool zypp::media::MediaAccess::isSharedMedia ( ) const
private

Definition at line 76 of file MediaAccess.cc.

◆ resetParentId()

void zypp::media::MediaAccess::resetParentId ( )
private

Definition at line 83 of file MediaAccess.cc.

◆ dependsOnParent() [1/2]

bool zypp::media::MediaAccess::dependsOnParent ( ) const
private

Definition at line 89 of file MediaAccess.cc.

◆ dependsOnParent() [2/2]

bool zypp::media::MediaAccess::dependsOnParent ( MediaAccessId  parentId,
bool  exactIdMatch 
) const
private

Definition at line 95 of file MediaAccess.cc.

◆ open()

void zypp::media::MediaAccess::open ( const Url url,
const Pathname preferred_attach_point = "" 
)

open url.

If preferred_attach_point is given, try to use it as attach point.

Caution: The medium can choose a different attach point. Only getAttachPoint() knows the real attach point.

Exceptions
MediaException

Definition at line 104 of file MediaAccess.cc.

◆ isOpen()

bool zypp::media::MediaAccess::isOpen ( ) const
inline

True if media is open.

Definition at line 100 of file MediaAccess.h.

◆ downloads()

bool zypp::media::MediaAccess::downloads ( ) const

Hint if files are downloaded or not.

Returns
True, if the files are downloaded.

Definition at line 211 of file MediaAccess.cc.

◆ protocol()

std::string zypp::media::MediaAccess::protocol ( ) const

Used Protocol if media is opened, otherwise 'unknown'.

Definition at line 202 of file MediaAccess.cc.

◆ url()

Url zypp::media::MediaAccess::url ( ) const

Url if media is opened, otherwise empty.

Definition at line 222 of file MediaAccess.cc.

◆ close()

void zypp::media::MediaAccess::close ( )

close url

Exceptions
MediaException

Definition at line 232 of file MediaAccess.cc.

◆ attach()

void zypp::media::MediaAccess::attach ( bool  next = false)

Use concrete handler to attach the media.

Parameters
nexttry next available device in turn until end of device list is reached (for media which are accessible through multiple devices like cdroms).
Exceptions
MediaException

Definition at line 256 of file MediaAccess.cc.

◆ isAttached()

bool zypp::media::MediaAccess::isAttached ( ) const

True if media is attached.

Exceptions
MediaException

Definition at line 266 of file MediaAccess.cc.

◆ hasMoreDevices()

bool zypp::media::MediaAccess::hasMoreDevices ( ) const

Definition at line 272 of file MediaAccess.cc.

◆ getDetectedDevices()

void zypp::media::MediaAccess::getDetectedDevices ( std::vector< std::string > &  devices,
unsigned int &  index 
) const
virtual

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
devicesvector to load with the device names
indexindex of the currently used device in the devices vector

Definition at line 279 of file MediaAccess.cc.

◆ localRoot()

Pathname zypp::media::MediaAccess::localRoot ( ) 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 better 'localPath( filename )'.

If media is not open an empty pathname is returned.

Definition at line 297 of file MediaAccess.cc.

◆ localPath()

Pathname zypp::media::MediaAccess::localPath ( const Pathname pathname) const

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

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

Definition at line 308 of file MediaAccess.cc.

◆ disconnect()

void zypp::media::MediaAccess::disconnect ( )

Use concrete handler to disconnect the media.

This is useful for media which e.g. holds open a connection to a server like FTP. After calling disconnect() the media object still is valid and files are present.

After calling disconnect() it's not possible to call provideFile() or provideDir() anymore.

Exceptions
MediaException

Definition at line 317 of file MediaAccess.cc.

◆ release()

void zypp::media::MediaAccess::release ( const std::string &  ejectDev = "")

Use concrete handler to release the media.

Parameters
ejectDevDevice to eject. None if empty.
Exceptions
MediaException

Definition at line 327 of file MediaAccess.cc.

◆ provideFile()

void zypp::media::MediaAccess::provideFile ( const Pathname filename,
const ByteCount expectedFileSize 
) const

Use concrete handler to provide file denoted by path below 'attach point'.

Filename is interpreted relative to the attached url and a path prefix is preserved.

Parameters
cachedIf cached is set to true, the function checks, if the file already exists and doesn't download it again if it does. Currently only the existence is checked, no other file attributes.
checkonlyIf this and 'cached' are set to true only the existence of the file is checked but it's not downloaded. If 'cached' is unset an errer is returned always.
Exceptions
MediaException

Definition at line 340 of file MediaAccess.cc.

◆ releaseFile()

void zypp::media::MediaAccess::releaseFile ( const Pathname filename) const

Remove filename below attach point IFF handler downloads files to the local filesystem.

Never remove anything from media.

Exceptions
MediaException

Definition at line 360 of file MediaAccess.cc.

◆ provideDir()

void zypp::media::MediaAccess::provideDir ( const Pathname dirname) const

Use concrete handler to provide directory denoted by path below 'attach point' (not recursive!).

'dirname' is interpreted relative to the attached url and a path prefix is preserved.

Exceptions
MediaException

Definition at line 373 of file MediaAccess.cc.

◆ provideDirTree()

void zypp::media::MediaAccess::provideDirTree ( const Pathname dirname) const

Use concrete handler to provide directory tree denoted by path below 'attach point' (recursive!!).

'dirname' is interpreted relative to the attached url and a path prefix is preserved.

Exceptions
MediaException

Definition at line 383 of file MediaAccess.cc.

◆ releaseDir()

void zypp::media::MediaAccess::releaseDir ( const Pathname dirname) const

Remove directory tree below attach point IFF handler downloads files to the local filesystem.

Never remove anything from media.

Exceptions
MediaException

Definition at line 393 of file MediaAccess.cc.

◆ releasePath()

void zypp::media::MediaAccess::releasePath ( const Pathname pathname) const

Remove pathname below attach point IFF handler downloads files to the local filesystem.

Never remove anything from media.

If pathname denotes a directory it is recursively removed. If pathname is empty or '/' everything below the attachpoint is recursively removed.

Exceptions
MediaException

Definition at line 402 of file MediaAccess.cc.

◆ setDeltafile()

void zypp::media::MediaAccess::setDeltafile ( const Pathname filename) const

set a deltafile to be used in the next download

Definition at line 350 of file MediaAccess.cc.

◆ dirInfo() [1/2]

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

Return content of directory on media via retlist.

If dots is false entries starting with '.' are not reported.

The request is forwarded to the concrete handler, which may atempt to retieve the content e.g. via 'readdir'

Caution: This is not supported by all media types. Be prepared to handle E_not_supported_by_media.

Exceptions
MediaException

Definition at line 412 of file MediaAccess.cc.

◆ dirInfo() [2/2]

void zypp::media::MediaAccess::dirInfo ( filesystem::DirContent retlist,
const Pathname dirname,
bool  dots = true 
) const

Basically the same as dirInfo above.

The content is returned as filesystem::DirContent, which includes name and filetype of each directory entry. Retrieving the filetype usg. requires an additional ::stat call for each entry, thus it's more expensive than a simple readdir.

Caution: This is not supported by all media types. Be prepared to handle E_not_supported_by_media.

Exceptions
MediaException

Definition at line 425 of file MediaAccess.cc.

◆ doesFileExist()

bool zypp::media::MediaAccess::doesFileExist ( const Pathname filename) const

check if a file exists

Asserted that url is a file and not a dir.

Exceptions
MediaException

Definition at line 438 of file MediaAccess.cc.

◆ dumpOn()

std::ostream & zypp::media::MediaAccess::dumpOn ( std::ostream &  str) const
virtual

Overload to realize std::ostream & operator<<.

Reimplemented from zypp::base::ReferenceCounted.

Definition at line 448 of file MediaAccess.cc.

◆ getFile()

void zypp::media::MediaAccess::getFile ( const Url from,
const Pathname to 
)

Get file from location at specified by URL and copy it to destination.

Parameters
fromSource URL
toDestination file name
Exceptions
MediaException

Definition at line 457 of file MediaAccess.cc.

Friends And Related Function Documentation

◆ MediaManager

friend class MediaManager
friend

Definition at line 66 of file MediaAccess.h.

◆ MediaManager_Impl

friend class MediaManager_Impl
friend

Definition at line 67 of file MediaAccess.h.

Member Data Documentation

◆ _noPath

const Pathname zypp::media::MediaAccess::_noPath
staticprivate

Definition at line 58 of file MediaAccess.h.

◆ _handler

MediaHandler* zypp::media::MediaAccess::_handler
private

handler for 'physical' media == 0 if not open

Definition at line 64 of file MediaAccess.h.


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