libzypp  17.14.0
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 
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
68 
74 
86 
92  Pathname _relativeRoot;
93 
99 
101  mutable time_t _attach_mtime;
102 
104  mutable Pathname _deltafile;
105 
106  protected:
110  const Url _url;
111 
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 
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 
246  findAttachedMedia(const MediaSourceRef &media) const;
247 
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 
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