zypp::media::MediaAccess Class Reference

Handle access to a medium. More...

#include <MediaAccess.h>

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

List of all members.

Classes

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

Public Types

typedef intrusive_ptr
< MediaAccess
Ptr
typedef intrusive_ptr< const
MediaAccess
constPtr

Public Member Functions

 MediaAccess ()
 constructor
void open (const Url &url, const Pathname &preferred_attach_point="")
 open url.
bool isOpen () const
 True if media is open.
bool downloads () const
 Hint if files are downloaded or not.
std::string protocol () const
 Used Protocol if media is opened, otherwise 'unknown'.
Url url () const
 Url if media is opened, otherwise empty.
void close ()
 close url
void attach (bool next=false)
 Use concrete handler to attach the media.
bool isAttached () const
 True if media is attached.
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.
Pathname localRoot () const
 Return the local directory that corresponds to medias url, no matter if media isAttached or not.
Pathname localPath (const Pathname &pathname) const
 Short for 'localRoot() + pathname', but returns an empty pathname if media is not open.
void disconnect ()
 Use concrete handler to disconnect the media.
void release (const std::string &ejectDev="")
 Use concrete handler to release the media.
void provideFile (const Pathname &filename) const
 Use concrete handler to provide file denoted by path below 'attach point'.
void releaseFile (const Pathname &filename) const
 Remove filename below attach point IFF handler downloads files to the local filesystem.
void provideDir (const Pathname &dirname) const
 Use concrete handler to provide directory denoted by path below 'attach point' (not recursive!).
void provideDirTree (const Pathname &dirname) const
 Use concrete handler to provide directory tree denoted by path below 'attach point' (recursive!!).
void releaseDir (const Pathname &dirname) const
 Remove directory tree below attach point IFF handler downloads files to the local filesystem.
void releasePath (const Pathname &pathname) const
 Remove pathname below attach point IFF handler downloads files to the local filesystem.
void dirInfo (std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
 Return content of directory on media via retlist.
void dirInfo (filesystem::DirContent &retlist, const Pathname &dirname, bool dots=true) const
 Basically the same as dirInfo above.
bool doesFileExist (const Pathname &filename) const
 check if a file exists
virtual ~MediaAccess ()
 Destructor.
virtual std::ostream & dumpOn (std::ostream &str) const
 Overload to realize std::ostream & operator<<.
void getFile (const Url &from, const Pathname &to)
 Get file from location at specified by URL and copy it to destination.

Static Public Member Functions

static ZYPP_DEPRECATED bool downloads (const Url &url)
static ZYPP_DEPRECATED bool canBeVolatile (const Url &url)

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

Static Private Attributes

static const Pathname _noPath

Friends

class MediaManager
class MediaManager_Impl


Detailed Description

Handle access to a medium.

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

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

Definition at line 53 of file MediaAccess.h.

typedef intrusive_ptr<const MediaAccess> zypp::media::MediaAccess::constPtr

Definition at line 54 of file MediaAccess.h.


Constructor & Destructor Documentation

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

constructor

Definition at line 53 of file MediaAccess.cc.

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

Destructor.

Definition at line 59 of file MediaAccess.cc.

References close().


Member Function Documentation

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

Definition at line 69 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::attachedMedia().

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

Definition at line 76 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::isSharedMedia().

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

Definition at line 83 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::resetParentId().

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

Definition at line 89 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::dependsOnParent().

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

Definition at line 95 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::dependsOnParent().

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.

References _handler, zypp::media::TransferSettings::addHeader(), close(), ERR, zypp::media::MediaAria2c::existsAria2cmd(), zypp::Url::getScheme(), zypp::Url::isValid(), MIL, zypp::media::UrlResolverPlugin::resolveUrl(), zypp::media::MediaCurl::settings(), url(), WAR, and ZYPP_THROW.

Referenced by getFile().

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

True if media is open.

Definition at line 100 of file MediaAccess.h.

References _handler.

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

Hint if files are downloaded or not.

Returns:
True, if the files are downloaded.

Definition at line 216 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::downloads().

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

static ZYPP_DEPRECATED bool zypp::media::MediaAccess::canBeVolatile ( const Url url  )  [inline, static]

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

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

Definition at line 207 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::protocol().

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

Url if media is opened, otherwise empty.

Definition at line 227 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::url().

Referenced by open().

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

close url

Exceptions:
MediaException 

Definition at line 237 of file MediaAccess.cc.

References _handler, MIL, zypp::media::MediaHandler::release(), WAR, ZYPP_CAUGHT, and ZYPP_RETHROW.

Referenced by open(), and ~MediaAccess().

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

Use concrete handler to attach the media.

Parameters:
next try 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 261 of file MediaAccess.cc.

References _handler, zypp::media::MediaHandler::attach(), and ZYPP_THROW.

Referenced by getFile().

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

True if media is attached.

Exceptions:
MediaException 

Definition at line 271 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::isAttached().

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

Definition at line 277 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::hasMoreDevices().

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

Definition at line 284 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::getDetectedDevices().

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 302 of file MediaAccess.cc.

References _handler, _noPath, and zypp::media::MediaHandler::localRoot().

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 313 of file MediaAccess.cc.

References _handler, _noPath, and zypp::media::MediaHandler::localPath().

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 322 of file MediaAccess.cc.

References _handler, zypp::media::MediaHandler::disconnect(), and ZYPP_THROW.

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

Use concrete handler to release the media.

Parameters:
ejectDev Device to eject. None if empty.
Exceptions:
MediaException 

Definition at line 332 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::release().

Referenced by getFile().

void zypp::media::MediaAccess::provideFile ( const Pathname &  filename  )  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:
cached If 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.
checkonly If 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 345 of file MediaAccess.cc.

References _handler, zypp::media::MediaHandler::provideFile(), and ZYPP_THROW.

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 355 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::releaseFile().

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 368 of file MediaAccess.cc.

References _handler, zypp::media::MediaHandler::provideDir(), and ZYPP_THROW.

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 378 of file MediaAccess.cc.

References _handler, zypp::media::MediaHandler::provideDirTree(), and ZYPP_THROW.

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 388 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::releaseDir().

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 397 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::releasePath().

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 407 of file MediaAccess.cc.

References _handler, zypp::media::MediaHandler::dirInfo(), and ZYPP_THROW.

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 420 of file MediaAccess.cc.

References _handler, zypp::media::MediaHandler::dirInfo(), and ZYPP_THROW.

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 433 of file MediaAccess.cc.

References _handler, zypp::media::MediaHandler::doesFileExist(), and ZYPP_THROW.

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 443 of file MediaAccess.cc.

References _handler, and zypp::media::MediaHandler::protocol().

Referenced by zypp::media::operator<<().

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:
from Source URL
to Destination file name
Exceptions:
MediaException 

Definition at line 452 of file MediaAccess.cc.

References _handler, attach(), DBG, zypp::Url::getPathData(), open(), zypp::media::MediaHandler::provideFileCopy(), release(), zypp::Url::setPathData(), and ZYPP_RETHROW.


Friends And Related Function Documentation

friend class MediaManager [friend]

Definition at line 66 of file MediaAccess.h.

friend class MediaManager_Impl [friend]

Definition at line 67 of file MediaAccess.h.


Member Data Documentation

const Pathname zypp::media::MediaAccess::_noPath [static, private]

Definition at line 58 of file MediaAccess.h.

Referenced by localPath(), and localRoot().


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

doxygen