libzypp: zypp/media/MediaHandler.h Source File

libzypp 17.38.14

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 <any>
17#include <iosfwd>
18#include <string>
19#include <list>
20
21#include <zypp-core/Pathname.h>
22#include <zypp/PathInfo.h>
23#include <zypp-core/base/PtrTypes.h>
24
25#include <zypp/media/MediaSource.h>
26#include <zypp-media/MediaException>
27#include <zypp-core/Globals.h>
28#include <zypp-core/OnMediaLocation>
29#include <zypp-core/MirroredOrigin.h>
30
31#undef ZYPP_BASE_LOGGER_LOGGROUP
32#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::media"
33
34namespace zypp {
35 namespace media {
36
37 class MediaManager;
38
40//
41// CLASS NAME : MediaHandler
50 class MediaHandler {
51 friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
52
53 public:
54 using Ptr = shared_ptr<MediaHandler>;
55 using constPtr = shared_ptr<const MediaHandler>;
56 static bool setAttachPrefix(const Pathname &attach_prefix);
57
58 static std::string getRealPath(const std::string &path);
59 static Pathname getRealPath(const Pathname &path);
60
61 private:
65 static Pathname _attachPrefix;
66
70 mutable
71 MediaSourceRef _mediaSource;
72
77 AttachPointRef _attachPoint;
78
89 AttachPoint _attachPointHint;
90
96 Pathname _relativeRoot;
97
102 bool _does_download;
103
105 mutable time_t _attach_mtime;
106
107 protected:
108
112 MirroredOrigin _origin;
113
117 MediaAccessId _parentId;
118
119 public:
120
127 bool dependsOnParent(MediaAccessId parentId,
128 bool exactIdMatch);
129 bool dependsOnParent();
130
136 void resetParentId();
137
141 Pathname attachPoint() const;
142
148 void setAttachPoint(const Pathname &path, bool temp);
149
154 void setAttachPoint(const AttachPointRef &ref);
155
159 AttachPoint attachPointHint() const;
160
166 void attachPointHint(const Pathname &path, bool temp);
167
175 Pathname createAttachPoint() const;
182 Pathname createAttachPoint(const Pathname &attach_root) const;
183
188 void removeAttachPoint();
189
196 virtual bool checkAttachPoint(const Pathname &apoint) const;
197
206 static bool checkAttachPoint(const Pathname &apoint,
207 bool empty_dir,
208 bool writeable);
209
218 bool isUseableAttachPoint(const Pathname &path,
219 bool mtab=true) const;
220
225 std::string mediaSourceName() const
226 {
227 return _mediaSource ? _mediaSource->name : "";
228 }
229
234 void setMediaSource(const MediaSourceRef &ref);
235
240 AttachedMedia
241 findAttachedMedia(const MediaSourceRef &media) const;
242
254 AttachedMedia attachedMedia() const;
255
260 bool isSharedMedia() const;
261
270 bool checkAttached(bool matchMountFs) const;
271
280 void forceRelaseAllMedia(bool matchMountFs);
281 void forceRelaseAllMedia(const MediaSourceRef &ref,
282 bool matchMountFs);
283
284 protected:
285
287 //
288 // Real action interface to be overloaded by concrete handler.
289 //
291
304 virtual void attachTo(bool next = false) = 0;
305
321 virtual void disconnectFrom() { return; }
322
335 virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
336
343 virtual void forceEject( const std::string & device ) {}
344
356 virtual void getFile( const OnMediaLocation &file ) const;
357
369 virtual void getFileCopy( const OnMediaLocation & file, const Pathname & targetFilename ) const;
370
371
387 virtual void getDir( const Pathname & dirname, bool recurse_r ) const = 0;
388
404 virtual void getDirInfo( std::list<std::string> & retlist,
405 const Pathname & dirname, bool dots = true ) const = 0;
406
418 virtual void getDirInfo( filesystem::DirContent & retlist,
419 const Pathname & dirname, bool dots = true ) const = 0;
420
429 virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
430
431 protected:
432
441 void getDirectoryYast( std::list<std::string> & retlist,
442 const Pathname & dirname, bool dots = true ) const;
443
452 void getDirectoryYast( filesystem::DirContent & retlist,
453 const Pathname & dirname, bool dots = true ) const;
454
455 public:
456
468 MediaHandler ( MirroredOrigin origin_r,
469 const Pathname & attach_point_r,
470 Pathname urlpath_below_attachpoint_r,
471 const bool does_download_r );
472
477 virtual ~MediaHandler();
478
479 public:
480
481
483 //
484 // MediaAccess interface. Does common checks and logging.
485 // Invokes real action if necessary.
486 //
488
492 bool downloads() const { return _does_download; }
493
497 std::string protocol() const { return _origin.scheme(); }
498
502 const MirroredOrigin &origin() const { return _origin; }
503
507 Url url() const { return _origin.authority().url(); }
508
512 OriginEndpoint originEndpoint() const { return _origin.authority(); }
513
524 void attach(bool next);
525
529 virtual bool isAttached() const { return _mediaSource != nullptr; }
530
539 Pathname localRoot() const;
540
546 Pathname localPath( const Pathname & pathname ) const;
547
561 void disconnect();
562
569 void release( const std::string & ejectDev = "" );
570
579 void provideFile( const OnMediaLocation &file ) const;
580
592 void provideFileCopy( const OnMediaLocation &srcFile, const Pathname& targetFilename ) const;
593
603 void provideDir( const Pathname& dirname ) const;
604
614 void provideDirTree( const Pathname& dirname ) const;
615
623 void releaseFile( const Pathname & filename ) const { return releasePath( filename ); }
624
632 void releaseDir( const Pathname & dirname ) const { return releasePath( dirname ); }
633
646 void releasePath( const Pathname& pathname ) const;
647
648 public:
649
663 void dirInfo( std::list<std::string> & retlist,
664 const Pathname & dirname, bool dots = true ) const;
665
678 void dirInfo( filesystem::DirContent & retlist,
679 const Pathname & dirname, bool dots = true ) const;
680
689 bool doesFileExist( const Pathname & filename ) const;
690
694 virtual bool hasMoreDevices();
695
704 virtual void
705 getDetectedDevices(std::vector<std::string> & devices,
706 unsigned int & index) const;
707
718 virtual void
719 precacheFiles ( const std::vector< OnMediaLocation > &files );
720};
721
723
724 } // namespace media
725} // namespace zypp
726
727
728#endif // ZYPP_MEDIA_MEDIAHANDLERL_H
Globals.h
Provides API related macros.
MediaSource.h
MirroredOrigin.h
Pathname.h
PtrTypes.h
shared_ptr
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
zypp::MirroredOrigin::scheme
std::string scheme() const
Definition MirroredOrigin.cc:297
zypp::MirroredOrigin::authority
const OriginEndpoint & authority() const
Definition MirroredOrigin.cc:205
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition onmedialocation.h:37
zypp::OriginEndpoint
Represents a single, configurable network endpoint, combining a URL with specific access settings.
Definition MirroredOrigin.h:41
zypp::OriginEndpoint::url
const zypp::Url & url() const
Definition MirroredOrigin.cc:53
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::media::AttachPoint
Attach point of a media source.
Definition MediaSource.h:107
zypp::media::MediaHandler
Abstract base class for 'physical' MediaHandler like MediaCD, etc.
Definition MediaHandler.h:50
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:416
zypp::media::MediaHandler::getFile
virtual void getFile(const OnMediaLocation &file) const
Call concrete handler to provide file below attach point.
Definition MediaHandler.cc:1188
zypp::media::MediaHandler::MediaHandler
MediaHandler(MirroredOrigin origin_r, const Pathname &attach_point_r, 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:55
zypp::media::MediaHandler::attachTo
virtual void attachTo(bool next=false)=0
Call concrete handler to attach the media.
zypp::media::MediaHandler::_origin
MirroredOrigin _origin
Contains the authority URL and mirrors.
Definition MediaHandler.h:112
zypp::media::MediaHandler::url
Url url() const
Primary Url used.
Definition MediaHandler.h:507
zypp::media::MediaHandler::provideDirTree
void provideDirTree(const Pathname &dirname) const
Use concrete handler to provide directory tree denoted by path below 'localRoot' (recursive!
Definition MediaHandler.cc:1008
zypp::media::MediaHandler::getDoesFileExist
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
Definition MediaHandler.cc:1326
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:1340
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:848
zypp::media::MediaHandler::disconnect
void disconnect()
Use concrete handler to isconnect media.
Definition MediaHandler.cc:687
zypp::media::MediaHandler::_mediaSource
MediaSourceRef _mediaSource
The attached media source description reference.
Definition MediaHandler.h:71
zypp::media::MediaHandler::constPtr
shared_ptr< const MediaHandler > constPtr
Definition MediaHandler.h:55
zypp::media::MediaHandler::attach
void attach(bool next)
Use concrete handler to attach the media.
Definition MediaHandler.cc:633
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:116
zypp::media::MediaHandler::_attach_mtime
time_t _attach_mtime
timestamp of the the last attach verification
Definition MediaHandler.h:105
zypp::media::MediaHandler::precacheFiles
virtual void precacheFiles(const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
Definition MediaHandler.cc:1351
zypp::media::MediaHandler::isAttached
virtual bool isAttached() const
True if media is attached.
Definition MediaHandler.h:529
zypp::media::MediaHandler::hasMoreDevices
virtual bool hasMoreDevices()
Check if the media has one more device available for attach(true).
Definition MediaHandler.cc:1335
zypp::media::MediaHandler::_attachPointHint
AttachPoint _attachPointHint
The user provided attach preferred point.
Definition MediaHandler.h:89
zypp::media::MediaHandler::disconnectFrom
virtual void disconnectFrom()
Call concrete handler to disconnect media.
Definition MediaHandler.h:321
zypp::media::MediaHandler::getRealPath
static std::string getRealPath(const std::string &path)
Definition MediaHandler.cc:122
zypp::media::MediaHandler::downloads
bool downloads() const
Hint if files are downloaded or not.
Definition MediaHandler.h:492
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:1053
zypp::media::MediaHandler::createAttachPoint
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
Definition MediaHandler.cc:312
zypp::media::MediaHandler::_attachPoint
AttachPointRef _attachPoint
This is where the media will be actually attached ("mounted").
Definition MediaHandler.h:77
zypp::media::MediaHandler::attachPointHint
AttachPoint attachPointHint() const
Get the actual attach point hint.
Definition MediaHandler.cc:255
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:632
zypp::media::MediaHandler::originEndpoint
OriginEndpoint originEndpoint() const
Primary OriginEndpoint used.
Definition MediaHandler.h:512
zypp::media::MediaHandler::doesFileExist
bool doesFileExist(const Pathname &filename) const
check if a file exists
Definition MediaHandler.cc:1097
zypp::media::MediaHandler::setAttachPrefix
static bool setAttachPrefix(const Pathname &attach_prefix)
Definition MediaHandler.cc:283
zypp::media::MediaHandler::dependsOnParent
bool dependsOnParent(MediaAccessId parentId, bool exactIdMatch)
Check if the current media handler depends on an another handler specified by media access id.
Definition MediaHandler.cc:928
zypp::media::MediaHandler::Ptr
shared_ptr< MediaHandler > Ptr
Definition MediaHandler.h:54
zypp::media::MediaHandler::mediaSourceName
std::string mediaSourceName() const
Get the media source name or an empty string.
Definition MediaHandler.h:225
zypp::media::MediaHandler::getFileCopy
virtual void getFileCopy(const OnMediaLocation &file, const Pathname &targetFilename) const
Call concrete handler to provide a file under a different place in the file system (usually not under...
Definition MediaHandler.cc:1201
zypp::media::MediaHandler::setMediaSource
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Definition MediaHandler.cc:432
zypp::media::MediaHandler::localPath
Pathname localPath(const Pathname &pathname) const
Files provided will be available at 'localPath(filename)'.
Definition MediaHandler.cc:664
zypp::media::MediaHandler::_attachPrefix
static Pathname _attachPrefix
User defined default attach point prefix.
Definition MediaHandler.h:65
zypp::media::MediaHandler::protocol
std::string protocol() const
Protocol hint for MediaAccess.
Definition MediaHandler.h:497
zypp::media::MediaHandler::origin
const MirroredOrigin & origin() const
Access the internal MirroredOrigin (authority and mirrors).
Definition MediaHandler.h:502
zypp::media::MediaHandler::operator<<
friend std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
Definition MediaHandler.cc:1181
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:778
zypp::media::MediaHandler::release
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
Definition MediaHandler.cc:704
zypp::media::MediaHandler::checkAttached
bool checkAttached(bool matchMountFs) const
Check actual mediaSource attachment against the current mount table of the system.
Definition MediaHandler.cc:479
zypp::media::MediaHandler::removeAttachPoint
void removeAttachPoint()
Remove unused attach point.
Definition MediaHandler.cc:143
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:1114
zypp::media::MediaHandler::setAttachPoint
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Definition MediaHandler.cc:200
zypp::media::MediaHandler::attachPoint
Pathname attachPoint() const
Return the currently used attach point.
Definition MediaHandler.cc:185
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:623
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:206
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:1219
zypp::media::MediaHandler::_relativeRoot
Pathname _relativeRoot
The relative root directory of the data on the media.
Definition MediaHandler.h:96
zypp::media::MediaHandler::findAttachedMedia
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Ask the media manager if specified media source is already attached.
Definition MediaHandler.cc:269
zypp::media::MediaHandler::provideDir
void provideDir(const Pathname &dirname) const
Use concrete handler to provide directory denoted by path below 'localRoot' (not recursive!...
Definition MediaHandler.cc:989
zypp::media::MediaHandler::isSharedMedia
bool isSharedMedia() const
Returns a hint if the media is shared or not.
Definition MediaHandler.cc:465
zypp::media::MediaHandler::provideFileCopy
void provideFileCopy(const OnMediaLocation &srcFile, const Pathname &targetFilename) const
Call concrete handler to provide a copy of a file under a different place in the file system (usually...
Definition MediaHandler.cc:957
zypp::media::MediaHandler::releaseFrom
virtual void releaseFrom(const std::string &ejectDev="")=0
Call concrete handler to release the media.
zypp::media::MediaHandler::provideFile
void provideFile(const OnMediaLocation &file) const
Use concrete handler to provide file denoted by path below 'localRoot'.
Definition MediaHandler.cc:969
zypp::media::MediaHandler::attachedMedia
AttachedMedia attachedMedia() const
Returns the attached media.
Definition MediaHandler.cc:448
zypp::media::MediaHandler::releasePath
void releasePath(const Pathname &pathname) const
Remove pathname below localRoot IFF handler downloads files to the local filesystem.
Definition MediaHandler.cc:1027
zypp::media::MediaHandler::forceEject
virtual void forceEject(const std::string &device)
Call concrete handler to physically eject the media (i.e.
Definition MediaHandler.h:343
zypp::media::MediaHandler::_does_download
bool _does_download
True if concrete handler downloads files to the local filesystem.
Definition MediaHandler.h:102
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:1241
zypp::media::MediaHandler::_parentId
MediaAccessId _parentId
Access Id of media handler we depend on.
Definition MediaHandler.h:117
str
String related utilities and Regular expression matching.
zypp::filesystem::DirContent
std::list< DirEntry > DirContent
Returned by readdir.
Definition PathInfo.h:534
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition MediaSource.h:30
zypp::media::MediaSourceRef
zypp::RW_pointer< MediaSource > MediaSourceRef
Definition MediaSource.h:125
zypp::media::AttachPointRef
zypp::RW_pointer< AttachPoint > AttachPointRef
Definition MediaSource.h:126
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::media::AttachedMedia
A simple structure containing references to a media source and its attach point.
Definition MediaSource.h:135
PathInfo.h