libzypp 17.37.17
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/Pathname.h>
22#include <zypp/PathInfo.h>
23#include <zypp/base/PtrTypes.h>
24
26#include <zypp-media/MediaException>
27#include <zypp-core/Globals.h>
28#include <zypp-core/OnMediaLocation>
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
51 friend std::ostream & operator<<( std::ostream & str, const MediaHandler & obj );
52
53 public:
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:
66
70 mutable
72
78
90
97
103
105 mutable time_t _attach_mtime;
106
107 protected:
108
113
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
160
166 void attachPointHint(const Pathname &path, bool temp);
167
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
242
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
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 Url url() const { return _origin.authority().url(); }
503
507 OriginEndpoint originEndpoint() const { return _origin.authority(); }
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( const OnMediaLocation &file ) const;
575
587 void provideFileCopy( const OnMediaLocation &srcFile, const Pathname& targetFilename ) const;
588
598 void provideDir( const Pathname& dirname ) const;
599
609 void provideDirTree( const 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( const Pathname& pathname ) const;
642
643 public:
644
658 void dirInfo( std::list<std::string> & retlist,
659 const Pathname & dirname, bool dots = true ) const;
660
673 void dirInfo( filesystem::DirContent & retlist,
674 const Pathname & dirname, bool dots = true ) const;
675
684 bool doesFileExist( const Pathname & filename ) const;
685
689 virtual bool hasMoreDevices();
690
699 virtual void
700 getDetectedDevices(std::vector<std::string> & devices,
701 unsigned int & index) const;
702
713 virtual void
714 precacheFiles ( const std::vector< OnMediaLocation > &files );
715};
716
718
719 } // namespace media
720} // namespace zypp
721
722
723#endif // ZYPP_MEDIA_MEDIAHANDLERL_H
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Describes a resource file located on a medium.
Represents a single, configurable network endpoint, combining a URL with specific access settings.
Url manipulation class.
Definition Url.h:93
Attach point of a media source.
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...
virtual void getFile(const OnMediaLocation &file) const
Call concrete handler to provide file below attach point.
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.
virtual void attachTo(bool next=false)=0
Call concrete handler to attach the media.
MirroredOrigin _origin
Contains the authority URL and mirrors.
Url url() const
Primary Url used.
void provideDirTree(const Pathname &dirname) const
Use concrete handler to provide directory tree denoted by path below 'localRoot' (recursive!
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
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 ...
virtual bool checkAttachPoint(const Pathname &apoint) const
Verify if the specified directory as attach point (root) as requires by the particular media handler ...
void disconnect()
Use concrete handler to isconnect media.
MediaSourceRef _mediaSource
The attached media source description reference.
shared_ptr< const MediaHandler > constPtr
void attach(bool next)
Use concrete handler to attach the media.
void resetParentId()
Called in case, where the media manager takes over the destruction of the parent id (e....
time_t _attach_mtime
timestamp of the the last attach verification
virtual void precacheFiles(const std::vector< OnMediaLocation > &files)
Tries to fetch the given files and precaches them.
virtual bool isAttached() const
True if media is attached.
virtual bool hasMoreDevices()
Check if the media has one more device available for attach(true).
AttachPoint _attachPointHint
The user provided attach preferred point.
virtual void disconnectFrom()
Call concrete handler to disconnect media.
static std::string getRealPath(const std::string &path)
bool downloads() const
Hint if files are downloaded or not.
void dirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Return content of directory on media via retlist.
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
AttachPointRef _attachPoint
This is where the media will be actually attached ("mounted").
AttachPoint attachPointHint() const
Get the actual attach point hint.
void releaseDir(const Pathname &dirname) const
Remove directory tree below localRoot IFF handler downloads files to the local filesystem.
OriginEndpoint originEndpoint() const
Primary OriginEndpoint used.
bool doesFileExist(const Pathname &filename) const
check if a file exists
static bool setAttachPrefix(const Pathname &attach_prefix)
shared_ptr< MediaHandler > Ptr
std::string mediaSourceName() const
Get the media source name or an empty string.
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...
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Pathname localPath(const Pathname &pathname) const
Files provided will be available at 'localPath(filename)'.
static Pathname _attachPrefix
User defined default attach point prefix.
std::string protocol() const
Protocol hint for MediaAccess.
friend std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
void forceRelaseAllMedia(bool matchMountFs)
Call to this function will try to release all media matching the currenlty attached media source,...
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
bool checkAttached(bool matchMountFs) const
Check actual mediaSource attachment against the current mount table of the system.
void removeAttachPoint()
Remove unused attach point.
void getDirectoryYast(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Retrieve and if available scan dirname/directory.yast.
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Pathname attachPoint() const
Return the currently used attach point.
void releaseFile(const Pathname &filename) const
Remove filename below localRoot IFF handler downloads files to the local filesystem.
Pathname localRoot() const
Return the local directory that corresponds to medias url, no matter if media isAttached or not.
virtual ~MediaHandler()
Contolling MediaAccess takes care, that attached media is released prior to deleting this.
virtual void getDir(const Pathname &dirname, bool recurse_r) const =0
Call concrete handler to provide directory content (not recursive!) below attach point.
Pathname _relativeRoot
The relative root directory of the data on the media.
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Ask the media manager if specified media source is already attached.
void provideDir(const Pathname &dirname) const
Use concrete handler to provide directory denoted by path below 'localRoot' (not recursive!...
bool isSharedMedia() const
Returns a hint if the media is shared or not.
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...
virtual void releaseFrom(const std::string &ejectDev="")=0
Call concrete handler to release the media.
void provideFile(const OnMediaLocation &file) const
Use concrete handler to provide file denoted by path below 'localRoot'.
AttachedMedia attachedMedia() const
Returns the attached media.
void releasePath(const Pathname &pathname) const
Remove pathname below localRoot IFF handler downloads files to the local filesystem.
virtual void forceEject(const std::string &device)
Call concrete handler to physically eject the media (i.e.
bool _does_download
True if concrete handler downloads files to the local filesystem.
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.
MediaAccessId _parentId
Access Id of media handler we depend on.
String related utilities and Regular expression matching.
std::list< DirEntry > DirContent
Returned by readdir.
Definition PathInfo.h:526
unsigned int MediaAccessId
Media manager access Id type.
Definition MediaSource.h:30
zypp::RW_pointer< MediaSource > MediaSourceRef
zypp::RW_pointer< AttachPoint > AttachPointRef
Easy-to use interface to the ZYPP dependency resolver.
A simple structure containing references to a media source and its attach point.
Provides API related macros.