libzypp  17.25.2
MediaHandler.h
Go to the documentation of this file.
1 
2 /*---------------------------------------------------------------------\
3 | ____ _ __ __ ___ |
4 | |__ / \ / / . \ . \ |
5 | / / \ V /| _/ _/ |
6 | / /__ | | | | | | |
7 | /_____||_| |_| |_| |
8 | |
9 \---------------------------------------------------------------------*/
13 #ifndef ZYPP_MEDIA_MEDIAHANDLERL_H
14 #define ZYPP_MEDIA_MEDIAHANDLERL_H
15 
16 #include <iosfwd>
17 #include <string>
18 #include <list>
19 
20 #include <zypp/Pathname.h>
21 #include <zypp/PathInfo.h>
22 #include <zypp/base/PtrTypes.h>
23 
24 #include <zypp/Url.h>
25 
26 #include <zypp/media/MediaSource.h>
28 #include <zypp/APIConfig.h>
29 #include <zypp/OnMediaLocation.h>
30 
31 namespace zypp {
32  namespace media {
33 
34 
36 //
37 // CLASS NAME : MediaHandler
46 class MediaHandler {
47  friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
48 
49  public:
50  typedef shared_ptr<MediaHandler> Ptr;
51  typedef shared_ptr<const MediaHandler> constPtr;
52 
53  static bool setAttachPrefix(const Pathname &attach_prefix);
54 
55  static std::string getRealPath(const std::string &path);
56  static Pathname getRealPath(const Pathname &path);
57 
58  private:
63 
67  mutable
69 
75 
87 
94 
100 
102  mutable time_t _attach_mtime;
103 
106 
107  protected:
111  const Url _url;
112 
117 
125  friend class MediaAccess;
126 
133  bool dependsOnParent(MediaAccessId parentId,
134  bool exactIdMatch);
135  bool dependsOnParent();
136 
142  void resetParentId();
143 
147  Pathname attachPoint() const;
148 
154  void setAttachPoint(const Pathname &path, bool temp);
155 
160  void setAttachPoint(const AttachPointRef &ref);
161 
166 
172  void attachPointHint(const Pathname &path, bool temp);
173 
181  Pathname createAttachPoint() const;
188  Pathname createAttachPoint(const Pathname &attach_root) const;
189 
194  void removeAttachPoint();
195 
202  virtual bool checkAttachPoint(const Pathname &apoint) const;
203 
212  static bool checkAttachPoint(const Pathname &apoint,
213  bool empty_dir,
214  bool writeable);
215 
224  bool isUseableAttachPoint(const Pathname &path,
225  bool mtab=true) const;
226 
231  std::string mediaSourceName() const
232  {
233  return _mediaSource ? _mediaSource->name : "";
234  }
235 
240  void setMediaSource(const MediaSourceRef &ref);
241 
247  findAttachedMedia(const MediaSourceRef &media) const;
248 
261 
266  bool isSharedMedia() const;
267 
276  bool checkAttached(bool matchMountFs) const;
277 
286  void forceRelaseAllMedia(bool matchMountFs);
287  void forceRelaseAllMedia(const MediaSourceRef &ref,
288  bool matchMountFs);
289 
290  protected:
291 
293  //
294  // Real action interface to be overloaded by concrete handler.
295  //
297 
310  virtual void attachTo(bool next = false) = 0;
311 
327  virtual void disconnectFrom() { return; }
328 
341  virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
342 
349  virtual void forceEject( const std::string & device ) {}
350 
362  virtual void getFile( const Pathname & filename, const ByteCount &expectedFileSize_r ) const;
363 
364 
375  virtual void getFiles( const std::vector< std::pair<Pathname, ByteCount> > &files ) const;
376 
388  virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, const ByteCount &expectedFileSize_r ) const;
389 
390 
406  virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
407 
423  virtual void getDirInfo( std::list<std::string> & retlist,
424  const Pathname & dirname, bool dots = true ) const = 0;
425 
437  virtual void getDirInfo( filesystem::DirContent & retlist,
438  const Pathname & dirname, bool dots = true ) const = 0;
439 
448  virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
449 
450  protected:
451 
460  void getDirectoryYast( std::list<std::string> & retlist,
461  const Pathname & dirname, bool dots = true ) const;
462 
472  const Pathname & dirname, bool dots = true ) const;
473 
474  public:
475 
487  MediaHandler ( const Url& url_r,
488  const Pathname & attach_point_r,
489  const Pathname & urlpath_below_attachpoint_r,
490  const bool does_download_r );
491 
496  virtual ~MediaHandler();
497 
498  public:
499 
500 
502  //
503  // MediaAccess interface. Does common checks and logging.
504  // Invokes real action if necessary.
505  //
507 
511  bool downloads() const { return _does_download; }
512 
516  std::string protocol() const { return _url.getScheme(); }
517 
521  Url url() const { return _url; }
522 
533  void attach(bool next);
534 
538  virtual bool isAttached() const { return _mediaSource != nullptr; }
539 
548  Pathname localRoot() const;
549 
555  Pathname localPath( const Pathname & pathname ) const;
556 
570  void disconnect();
571 
578  void release( const std::string & ejectDev = "" );
579 
588  void provideFile( Pathname filename, const ByteCount &expectedFileSize_r ) const;
589 
601  void provideFileCopy( Pathname srcFilename, Pathname targetFilename, const ByteCount &expectedFileSize_r ) const;
602 
612  void provideDir( Pathname dirname ) const;
613 
623  void provideDirTree( Pathname dirname ) const;
624 
632  void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
633 
641  void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
642 
655  void releasePath( Pathname pathname ) const;
656 
657  /*
658  * set a deltafile to be used in the next download
659  */
660  void setDeltafile( const Pathname &filename = Pathname()) const;
661 
662  /*
663  * return the deltafile set with setDeltafile()
664  */
665  Pathname deltafile () const;
666 
667  public:
668 
682  void dirInfo( std::list<std::string> & retlist,
683  const Pathname & dirname, bool dots = true ) const;
684 
697  void dirInfo( filesystem::DirContent & retlist,
698  const Pathname & dirname, bool dots = true ) const;
699 
708  bool doesFileExist( const Pathname & filename ) const;
709 
713  virtual bool hasMoreDevices();
714 
723  virtual void
724  getDetectedDevices(std::vector<std::string> & devices,
725  unsigned int & index) const;
726 
737  virtual void
738  precacheFiles ( const std::vector< OnMediaLocation > &files );
739 };
740 
742 
743  } // namespace media
744 } // namespace zypp
745 
746 
747 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
748 
749 
zypp::media::MediaHandler::_parentId
MediaAccessId _parentId
Access Id of media handler we depend on.
Definition: MediaHandler.h:116
zypp::media::MediaHandler::localRoot
Pathname localRoot() const
Return the local directory that corresponds to medias url, no matter if media isAttached or not.
Definition: MediaHandler.cc:236
zypp::media::MediaHandler::mediaSourceName
std::string mediaSourceName() const
Get the media source name or an empty string.
Definition: MediaHandler.h:231
zypp::media::MediaHandler::getFiles
virtual void getFiles(const std::vector< std::pair< Pathname, ByteCount > > &files) const
Call concrete handler to provide all files below attach point.
Definition: MediaHandler.cc:1247
zypp::media::MediaHandler::provideDirTree
void provideDirTree(Pathname dirname) const
Use concrete handler to provide directory tree denoted by path below 'localRoot' (recursive!...
Definition: MediaHandler.cc:1045
zypp::media::MediaHandler::_attach_mtime
time_t _attach_mtime
timestamp of the the last attach verification
Definition: MediaHandler.h:102
zypp::Url::getScheme
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:528
zypp::media::MediaHandler::doesFileExist
bool doesFileExist(const Pathname &filename) const
check if a file exists
Definition: MediaHandler.cc:1134
PathInfo.h
zypp::media::MediaHandler::resetParentId
void resetParentId()
Called in case, where the media manager takes over the destruction of the parent id (e....
Definition: MediaHandler.cc:115
zypp::media::MediaAccess
Handle access to a medium.
Definition: MediaAccess.h:52
zypp::media::MediaHandler::releaseFrom
virtual void releaseFrom(const std::string &ejectDev="")=0
Call concrete handler to release the media.
zypp::media::MediaHandler::releasePath
void releasePath(Pathname pathname) const
Remove pathname below localRoot IFF handler downloads files to the local filesystem.
Definition: MediaHandler.cc:1064
zypp::media::MediaHandler::getDirectoryYast
void getDirectoryYast(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Retrieve and if available scan dirname/directory.yast.
Definition: MediaHandler.cc:1151
zypp::media::MediaHandler::getFile
virtual void getFile(const Pathname &filename, const ByteCount &expectedFileSize_r) const
Call concrete handler to provide file below attach point.
Definition: MediaHandler.cc:1234
zypp::media::MediaHandler::_deltafile
Pathname _deltafile
file usable for delta downloads
Definition: MediaHandler.h:105
zypp::media::MediaHandler::hasMoreDevices
virtual bool hasMoreDevices()
Check if the media has one more device available for attach(true).
Definition: MediaHandler.cc:1390
zypp::media::MediaHandler::deltafile
Pathname deltafile() const
Definition: MediaHandler.cc:1416
zypp::media::MediaHandler::isSharedMedia
bool isSharedMedia() const
Returns a hint if the media is shared or not.
Definition: MediaHandler.cc:495
zypp::media::MediaHandler
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:46
zypp::media::MediaHandler::isAttached
virtual bool isAttached() const
True if media is attached.
Definition: MediaHandler.h:538
zypp::media::MediaHandler::dependsOnParent
bool dependsOnParent()
Definition: MediaHandler.cc:958
zypp::media::MediaHandler::isUseableAttachPoint
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Ask media manager, if the specified path is already used as attach point or if there are another atta...
Definition: MediaHandler.cc:446
PtrTypes.h
zypp::media::MediaHandler::attachedMedia
AttachedMedia attachedMedia() const
Returns the attached media.
Definition: MediaHandler.cc:478
Pathname.h
zypp::media::MediaHandler::setMediaSource
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Definition: MediaHandler.cc:462
zypp::media::MediaHandler::forceEject
virtual void forceEject(const std::string &device)
Call concrete handler to physically eject the media (i.e.
Definition: MediaHandler.h:349
zypp::media::MediaHandler::forceRelaseAllMedia
void forceRelaseAllMedia(bool matchMountFs)
Call to this function will try to release all media matching the currenlty attached media source,...
Definition: MediaHandler.cc:814
zypp::media::MediaHandler::findAttachedMedia
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Ask the media manager if specified media source is already attached.
Definition: MediaHandler.cc:299
zypp::media::MediaHandler::setDeltafile
void setDeltafile(const Pathname &filename=Pathname()) const
Definition: MediaHandler.cc:1411
MediaSource.h
zypp::ByteCount
Store and operate with byte count.
Definition: ByteCount.h:31
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
OnMediaLocation.h
zypp::media::MediaHandler::_relativeRoot
Pathname _relativeRoot
The relative root directory of the data on the media.
Definition: MediaHandler.h:93
zypp::media::MediaHandler::getRealPath
static std::string getRealPath(const std::string &path)
Definition: MediaHandler.cc:121
zypp::RW_pointer< MediaSource >
Url.h
zypp::media::MediaHandler::provideFile
void provideFile(Pathname filename, const ByteCount &expectedFileSize_r) const
Use concrete handler to provide file denoted by path below 'localRoot'.
Definition: MediaHandler.cc:1006
zypp::media::MediaHandler::setAttachPoint
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Definition: MediaHandler.cc:230
zypp::media::MediaHandler::dirInfo
void dirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Return content of directory on media via retlist.
Definition: MediaHandler.cc:1090
zypp::media::AttachedMedia
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:134
zypp::media::MediaHandler::_attachPoint
AttachPointRef _attachPoint
This is where the media will be actually attached ("mounted").
Definition: MediaHandler.h:74
zypp::media::MediaHandler::disconnect
void disconnect()
Use concrete handler to isconnect media.
Definition: MediaHandler.cc:723
zypp::media::MediaHandler::releaseDir
void releaseDir(const Pathname &dirname) const
Remove directory tree below localRoot IFF handler downloads files to the local filesystem.
Definition: MediaHandler.h:641
zypp::media::MediaHandler::provideDir
void provideDir(Pathname dirname) const
Use concrete handler to provide directory denoted by path below 'localRoot' (not recursive!...
Definition: MediaHandler.cc:1026
MediaException.h
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
zypp::media::MediaHandler::checkAttached
bool checkAttached(bool matchMountFs) const
Check actual mediaSource attachment against the current mount table of the system.
Definition: MediaHandler.cc:509
zypp::media::MediaHandler::constPtr
shared_ptr< const MediaHandler > constPtr
Definition: MediaHandler.h:51
zypp::media::MediaHandler::Ptr
shared_ptr< MediaHandler > Ptr
Definition: MediaHandler.h:50
zypp::media::MediaHandler::localPath
Pathname localPath(const Pathname &pathname) const
Files provided will be available at 'localPath(filename)'.
Definition: MediaHandler.cc:700
zypp::media::MediaHandler::url
Url url() const
Url used.
Definition: MediaHandler.h:521
zypp::media::MediaHandler::attachPointHint
AttachPoint attachPointHint() const
Get the actual attach point hint.
Definition: MediaHandler.cc:285
zypp::media::AttachPoint
Attach point of a media source.
Definition: MediaSource.h:106
zypp::media::MediaHandler::downloads
bool downloads() const
Hint if files are downloaded or not.
Definition: MediaHandler.h:511
zypp::media::MediaHandler::_mediaSource
MediaSourceRef _mediaSource
The attached media source description reference.
Definition: MediaHandler.h:68
zypp::media::MediaHandler::removeAttachPoint
void removeAttachPoint()
Remove unused attach point.
Definition: MediaHandler.cc:173
zypp::media::MediaHandler::getDetectedDevices
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 ...
Definition: MediaHandler.cc:1395
zypp::media::MediaHandler::~MediaHandler
virtual ~MediaHandler()
Contolling MediaAccess takes care, that attached media is released prior to deleting this.
Definition: MediaHandler.cc:105
zypp::media::MediaHandler::attach
void attach(bool next)
Use concrete handler to attach the media.
Definition: MediaHandler.cc:669
zypp::media::MediaHandler::attachPoint
Pathname attachPoint() const
Return the currently used attach point.
Definition: MediaHandler.cc:215
zypp::media::MediaHandler::operator<<
friend std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
Definition: MediaHandler.cc:1218
zypp::media::MediaHandler::_attachPointHint
AttachPoint _attachPointHint
The user provided attach preferred point.
Definition: MediaHandler.h:86
zypp::media::MediaHandler::checkAttachPoint
virtual bool checkAttachPoint(const Pathname &apoint) const
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
Definition: MediaHandler.cc:884
zypp::media::MediaHandler::precacheFiles
virtual void precacheFiles(const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
Definition: MediaHandler.cc:1406
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::media::MediaHandler::_url
const Url _url
Url to handle.
Definition: MediaHandler.h:111
zypp::media::MediaHandler::createAttachPoint
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
Definition: MediaHandler.cc:342
zypp::media::MediaHandler::protocol
std::string protocol() const
Protocol hint for MediaAccess.
Definition: MediaHandler.h:516
zypp::media::MediaHandler::provideFileCopy
void provideFileCopy(Pathname srcFilename, Pathname targetFilename, const ByteCount &expectedFileSize_r) const
Call concrete handler to provide a copy of a file under a different place in the file system (usually...
Definition: MediaHandler.cc:993
zypp::media::MediaHandler::setAttachPrefix
static bool setAttachPrefix(const Pathname &attach_prefix)
Definition: MediaHandler.cc:313
zypp::media::MediaHandler::_attachPrefix
static Pathname _attachPrefix
User defined default attach point prefix.
Definition: MediaHandler.h:62
str
String related utilities and Regular expression matching.
zypp::media::MediaHandler::release
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Definition: MediaHandler.cc:740
zypp::Url
Url manipulation class.
Definition: Url.h:88
zypp::media::MediaHandler::disconnectFrom
virtual void disconnectFrom()
Call concrete handler to disconnect media.
Definition: MediaHandler.h:327
zypp::media::MediaHandler::getDir
virtual void getDir(const Pathname &dirname, bool recurse_r) const =0
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition: MediaHandler.cc:1274
zypp::media::MediaHandler::releaseFile
void releaseFile(const Pathname &filename) const
Remove filename below localRoot IFF handler downloads files to the local filesystem.
Definition: MediaHandler.h:632
zypp::media::MediaHandler::attachTo
virtual void attachTo(bool next=false)=0
Call concrete handler to attach the media.
zypp::media::MediaHandler::getDoesFileExist
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
Definition: MediaHandler.cc:1381
zypp::media::MediaHandler::getDirInfo
virtual void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const =0
Call concrete handler to provide a content list of directory on media via retlist.
Definition: MediaHandler.cc:1296
zypp::media::MediaHandler::getFileCopy
virtual void getFileCopy(const Pathname &srcFilename, const Pathname &targetFilename, const ByteCount &expectedFileSize_r) const
Call concrete handler to provide a file under a different place in the file system (usually not under...
Definition: MediaHandler.cc:1254
zypp::media::MediaHandler::_does_download
bool _does_download
True if concrete handler downloads files to the local filesystem.
Definition: MediaHandler.h:99
zypp::media::MediaHandler::MediaHandler
MediaHandler(const Url &url_r, const Pathname &attach_point_r, const Pathname &urlpath_below_attachpoint_r, const bool does_download_r)
If the concrete media handler provides a nonempty attach_point, it must be an existing directory.
Definition: MediaHandler.cc:54