libzypp: zypp/media/MediaHandler.h Source File

libzypp 17.25.10

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>
27 #include <zypp/media/MediaException.h>
28 #include <zypp/APIConfig.h>
29
30 namespace zypp {
31 namespace media {
32
33
35 //
36 // CLASS NAME : MediaHandler
45 class MediaHandler {
46 friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
47
48 public:
49 typedef shared_ptr<MediaHandler> Ptr;
50 typedef shared_ptr<const MediaHandler> constPtr;
51
52 static bool setAttachPrefix(const Pathname &attach_prefix);
53
54 static std::string getRealPath(const std::string &path);
55 static Pathname getRealPath(const Pathname &path);
56
57 private:
61 static Pathname _attachPrefix;
62
66 mutable
67 MediaSourceRef _mediaSource;
68
73 AttachPointRef _attachPoint;
74
85 AttachPoint _attachPointHint;
86
92 Pathname _relativeRoot;
93
98 bool _does_download;
99
101 mutable time_t _attach_mtime;
102
104 mutable Pathname _deltafile;
105
106 protected:
110 const Url _url;
111
115 MediaAccessId _parentId;
116
124 friend class MediaAccess;
125
132 bool dependsOnParent(MediaAccessId parentId,
133 bool exactIdMatch);
134 bool dependsOnParent();
135
141 void resetParentId();
142
146 Pathname attachPoint() const;
147
153 void setAttachPoint(const Pathname &path, bool temp);
154
159 void setAttachPoint(const AttachPointRef &ref);
160
164 AttachPoint attachPointHint() const;
165
171 void attachPointHint(const Pathname &path, bool temp);
172
180 Pathname createAttachPoint() const;
187 Pathname createAttachPoint(const Pathname &attach_root) const;
188
193 void removeAttachPoint();
194
201 virtual bool checkAttachPoint(const Pathname &apoint) const;
202
211 static bool checkAttachPoint(const Pathname &apoint,
212 bool empty_dir,
213 bool writeable);
214
223 bool isUseableAttachPoint(const Pathname &path,
224 bool mtab=true) const;
225
230 std::string mediaSourceName() const
231 {
232 return _mediaSource ? _mediaSource->name : "";
233 }
234
239 void setMediaSource(const MediaSourceRef &ref);
240
245 AttachedMedia
246 findAttachedMedia(const MediaSourceRef &media) const;
247
259 AttachedMedia attachedMedia() const;
260
265 bool isSharedMedia() const;
266
275 bool checkAttached(bool matchMountFs) const;
276
285 void forceRelaseAllMedia(bool matchMountFs);
286 void forceRelaseAllMedia(const MediaSourceRef &ref,
287 bool matchMountFs);
288
289 protected:
290
292 //
293 // Real action interface to be overloaded by concrete handler.
294 //
296
309 virtual void attachTo(bool next = false) = 0;
310
326 virtual void disconnectFrom() { return; }
327
340 virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
341
348 virtual void forceEject( const std::string & device ) {}
349
361 virtual void getFile( const Pathname & filename, const ByteCount &expectedFileSize_r ) const;
362
374 virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, const ByteCount &expectedFileSize_r ) const;
375
376
392 virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
393
409 virtual void getDirInfo( std::list<std::string> & retlist,
410 const Pathname & dirname, bool dots = true ) const = 0;
411
423 virtual void getDirInfo( filesystem::DirContent & retlist,
424 const Pathname & dirname, bool dots = true ) const = 0;
425
434 virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
435
436 protected:
437
446 void getDirectoryYast( std::list<std::string> & retlist,
447 const Pathname & dirname, bool dots = true ) const;
448
457 void getDirectoryYast( filesystem::DirContent & retlist,
458 const Pathname & dirname, bool dots = true ) const;
459
460 public:
461
473 MediaHandler ( const Url& url_r,
474 const Pathname & attach_point_r,
475 const Pathname & urlpath_below_attachpoint_r,
476 const bool does_download_r );
477
482 virtual ~MediaHandler();
483
484 public:
485
486
488 //
489 // MediaAccess interface. Does common checks and logging.
490 // Invokes real action if necessary.
491 //
493
497 bool downloads() const { return _does_download; }
498
502 std::string protocol() const { return _url.getScheme(); }
503
507 Url url() const { return _url; }
508
519 void attach(bool next);
520
524 virtual bool isAttached() const { return _mediaSource != nullptr; }
525
534 Pathname localRoot() const;
535
541 Pathname localPath( const Pathname & pathname ) const;
542
556 void disconnect();
557
564 void release( const std::string & ejectDev = "" );
565
574 void provideFile( Pathname filename, const ByteCount &expectedFileSize_r ) const;
575
587 void provideFileCopy( Pathname srcFilename, Pathname targetFilename, const ByteCount &expectedFileSize_r ) const;
588
598 void provideDir( Pathname dirname ) const;
599
609 void provideDirTree( Pathname dirname ) const;
610
618 void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
619
627 void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
628
641 void releasePath( Pathname pathname ) const;
642
643 /*
644 * set a deltafile to be used in the next download
645 */
646 void setDeltafile( const Pathname &filename = Pathname()) const;
647
648 /*
649 * return the deltafile set with setDeltafile()
650 */
651 Pathname deltafile () const;
652
653 public:
654
668 void dirInfo( std::list<std::string> & retlist,
669 const Pathname & dirname, bool dots = true ) const;
670
683 void dirInfo( filesystem::DirContent & retlist,
684 const Pathname & dirname, bool dots = true ) const;
685
694 bool doesFileExist( const Pathname & filename ) const;
695
699 virtual bool hasMoreDevices();
700
709 virtual void
710 getDetectedDevices(std::vector<std::string> & devices,
711 unsigned int & index) const;
712 };
713
715
716 } // namespace media
717 } // namespace zypp
718
719
720 #endif // ZYPP_MEDIA_MEDIAHANDLERL_H
721
722
MediaException.h
MediaSource.h
PathInfo.h
Pathname.h
PtrTypes.h
Url.h
zypp::ByteCount
Store and operate with byte count.
Definition: ByteCount.h:31
zypp::Url
Url manipulation class.
Definition: Url.h:92
zypp::Url::getScheme
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:528
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::media::AttachPoint
Attach point of a media source.
Definition: MediaSource.h:106
zypp::media::MediaAccess
Handle access to a medium.
Definition: MediaAccess.h:51
zypp::media::MediaHandler
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
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
zypp::media::MediaHandler::attachTo
virtual void attachTo(bool next=false)=0
Call concrete handler to attach the media.
zypp::media::MediaHandler::url
Url url() const
Url used.
Definition: MediaHandler.h:507
zypp::media::MediaHandler::getDoesFileExist
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
Definition: MediaHandler.cc:1375
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:1389
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::deltafile
Pathname deltafile() const
Definition: MediaHandler.cc:1405
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
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::disconnect
void disconnect()
Use concrete handler to isconnect media.
Definition: MediaHandler.cc:723
zypp::media::MediaHandler::_mediaSource
MediaSourceRef _mediaSource
The attached media source description reference.
Definition: MediaHandler.h:67
zypp::media::MediaHandler::constPtr
shared_ptr< const MediaHandler > constPtr
Definition: MediaHandler.h:50
zypp::media::MediaHandler::attach
void attach(bool next)
Use concrete handler to attach the media.
Definition: MediaHandler.cc:669
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::MediaHandler::_attach_mtime
time_t _attach_mtime
timestamp of the the last attach verification
Definition: MediaHandler.h:101
zypp::media::MediaHandler::isAttached
virtual bool isAttached() const
True if media is attached.
Definition: MediaHandler.h:524
zypp::media::MediaHandler::hasMoreDevices
virtual bool hasMoreDevices()
Check if the media has one more device available for attach(true).
Definition: MediaHandler.cc:1384
zypp::media::MediaHandler::_attachPointHint
AttachPoint _attachPointHint
The user provided attach preferred point.
Definition: MediaHandler.h:85
zypp::media::MediaHandler::disconnectFrom
virtual void disconnectFrom()
Call concrete handler to disconnect media.
Definition: MediaHandler.h:326
zypp::media::MediaHandler::getRealPath
static std::string getRealPath(const std::string &path)
Definition: MediaHandler.cc:121
zypp::media::MediaHandler::downloads
bool downloads() const
Hint if files are downloaded or not.
Definition: MediaHandler.h:497
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::MediaHandler::createAttachPoint
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
Definition: MediaHandler.cc:342
zypp::media::MediaHandler::_attachPoint
AttachPointRef _attachPoint
This is where the media will be actually attached ("mounted").
Definition: MediaHandler.h:73
zypp::media::MediaHandler::attachPointHint
AttachPoint attachPointHint() const
Get the actual attach point hint.
Definition: MediaHandler.cc:285
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:627
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::doesFileExist
bool doesFileExist(const Pathname &filename) const
check if a file exists
Definition: MediaHandler.cc:1134
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::setAttachPrefix
static bool setAttachPrefix(const Pathname &attach_prefix)
Definition: MediaHandler.cc:313
zypp::media::MediaHandler::mediaSourceName
std::string mediaSourceName() const
Get the media source name or an empty string.
Definition: MediaHandler.h:230
zypp::media::MediaHandler::setMediaSource
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Definition: MediaHandler.cc:462
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::_attachPrefix
static Pathname _attachPrefix
User defined default attach point prefix.
Definition: MediaHandler.h:61
zypp::media::MediaHandler::protocol
std::string protocol() const
Protocol hint for MediaAccess.
Definition: MediaHandler.h:502
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::_url
const Url _url
Url to handle.
Definition: MediaHandler.h:110
zypp::media::MediaHandler::release
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Definition: MediaHandler.cc:740
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::removeAttachPoint
void removeAttachPoint()
Remove unused attach point.
Definition: MediaHandler.cc:173
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::setAttachPoint
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Definition: MediaHandler.cc:230
zypp::media::MediaHandler::attachPoint
Pathname attachPoint() const
Return the currently used attach point.
Definition: MediaHandler.cc:215
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:618
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::dependsOnParent
bool dependsOnParent()
Definition: MediaHandler.cc:958
zypp::media::MediaHandler::operator<<
friend std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
Definition: MediaHandler.cc:1218
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
zypp::media::MediaHandler::Ptr
shared_ptr< MediaHandler > Ptr
Definition: MediaHandler.h:49
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::setDeltafile
void setDeltafile(const Pathname &filename=Pathname()) const
Definition: MediaHandler.cc:1400
zypp::media::MediaHandler::_deltafile
Pathname _deltafile
file usable for delta downloads
Definition: MediaHandler.h:104
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:1248
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:1268
zypp::media::MediaHandler::_relativeRoot
Pathname _relativeRoot
The relative root directory of the data on the media.
Definition: MediaHandler.h:92
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::isSharedMedia
bool isSharedMedia() const
Returns a hint if the media is shared or not.
Definition: MediaHandler.cc:495
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::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::releaseFrom
virtual void releaseFrom(const std::string &ejectDev="")=0
Call concrete handler to release the media.
zypp::media::MediaHandler::attachedMedia
AttachedMedia attachedMedia() const
Returns the attached media.
Definition: MediaHandler.cc:478
zypp::media::MediaHandler::forceEject
virtual void forceEject(const std::string &device)
Call concrete handler to physically eject the media (i.e.
Definition: MediaHandler.h:348
zypp::media::MediaHandler::_does_download
bool _does_download
True if concrete handler downloads files to the local filesystem.
Definition: MediaHandler.h:98
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:1290
zypp::media::MediaHandler::_parentId
MediaAccessId _parentId
Access Id of media handler we depend on.
Definition: MediaHandler.h:115
str
String related utilities and Regular expression matching.
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::RW_pointer< MediaSource >
zypp::media::AttachedMedia
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:134