Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / media / MediaHandler.h
index f426a85..9fd8782 100644 (file)
@@ -1,3 +1,4 @@
+
 /*---------------------------------------------------------------------\
 |                          ____ _   __ __ ___                          |
 |                         |__  / \ / / . \ . \                         |
@@ -24,6 +25,7 @@
 
 #include "zypp/media/MediaSource.h"
 #include "zypp/media/MediaException.h"
+#include "zypp/APIConfig.h"
 
 namespace zypp {
   namespace media {
@@ -49,6 +51,9 @@ class MediaHandler {
 
        static bool setAttachPrefix(const Pathname &attach_prefix);
 
+       static std::string getRealPath(const std::string &path);
+       static Pathname    getRealPath(const Pathname    &path);
+
     private:
         /**
         * User defined default attach point prefix.
@@ -77,7 +82,7 @@ class MediaHandler {
         *
         *      dir, false => user specified attach point (not removed)
         */
-       AttachPoint     _AttachPointHint;
+       AttachPoint     _attachPointHint;
 
        /**
         * The relative root directory of the data on the media.
@@ -95,6 +100,9 @@ class MediaHandler {
         /** timestamp of the the last attach verification */
         mutable time_t  _attach_mtime;
 
+       /** file usable for delta downloads */
+       mutable Pathname _deltafile;
+
     protected:
         /**
         * Url to handle
@@ -164,9 +172,10 @@ class MediaHandler {
 
        /**
         * Try to create a default / temporary attach point.
-        * It trys to create it in attachPrefix if avaliable,
+        * It tries to create it in attachPrefix if avaliable,
         * then in built-in directories.
-        * \return The name of the new attach point or empty path name.
+        * \throws MediaBadAttachPointException if no attach point can be created
+        * \return The name of the new attach point
         */
        Pathname         createAttachPoint() const;
        /**
@@ -208,9 +217,11 @@ class MediaHandler {
         * as attach point or if there are another attach points
         * bellow of it.
         * \param path The attach point path to check.
+        * \param mtab Whether to check against the mtab, too.
         * \return True, if the path can be used as attach point.
         */
-        bool             isUseableAttachPoint(const Pathname &path) const;
+        bool             isUseableAttachPoint(const Pathname &path,
+                                             bool            mtab=true) const;
 
        /**
         * Get the media source name or an empty string.
@@ -272,6 +283,8 @@ class MediaHandler {
         *        while compare of a mount entry with mediaSource.
         */
        void             forceRelaseAllMedia(bool matchMountFs);
+       void             forceRelaseAllMedia(const MediaSourceRef &ref,
+                                            bool matchMountFs);
 
     protected:
 
@@ -319,11 +332,12 @@ class MediaHandler {
         * instance only, physically eject the media (i.e. CD-ROM).
         *
         * Asserted that media is attached.
+        * \param ejectDev Device to eject. None if empty.
         *
         * \throws MediaException
         *
         **/
-       virtual void releaseFrom( bool eject ) = 0;
+       virtual void releaseFrom( const std::string & ejectDev = "" ) = 0;
 
        /**
         * Call concrete handler to physically eject the media (i.e. CD-ROM)
@@ -331,7 +345,7 @@ class MediaHandler {
         *
         * Asserted that media is not attached.
         **/
-       virtual void forceEject() {}
+       virtual void forceEject( const std::string & device ) {}
 
        /**
         * Call concrete handler to provide file below attach point.
@@ -409,6 +423,16 @@ class MediaHandler {
         virtual void getDirInfo( filesystem::DirContent & retlist,
                                  const Pathname & dirname, bool dots = true ) const = 0;
 
+        /**
+         * check if a file exists
+         *
+         * Asserted that url is a file and not a dir.
+         *
+         * \throws MediaException
+         *
+         **/
+        virtual bool getDoesFileExist( const Pathname & filename ) const = 0;
+
   protected:
 
         /**
@@ -497,7 +521,7 @@ class MediaHandler {
        /**
         * True if media is attached.
         **/
-       virtual bool isAttached() const { return _mediaSource; }
+       virtual bool isAttached() const { return _mediaSource != nullptr; }
 
        /**
         * Return the local directory that corresponds to medias url,
@@ -533,12 +557,11 @@ class MediaHandler {
 
        /**
         * Use concrete handler to release the media.
-        * @param eject if true, physically eject the media * (i.e. CD-ROM)
+        * @param eject Device to physically eject. None if empty.
         *
         * \throws MediaException
-        *
         **/
-       void release( bool eject = false );
+       void release( const std::string & ejectDev = "" );
 
        /**
         * Use concrete handler to provide file denoted by path below
@@ -617,6 +640,16 @@ class MediaHandler {
         **/
        void releasePath( Pathname pathname ) const;
 
+        /*
+         * set a deltafile to be used in the next download
+         */
+       void setDeltafile( const Pathname &filename = Pathname()) const;
+
+       /*
+        * return the deltafile set with setDeltafile()
+        */
+       Pathname deltafile () const;
+
     public:
 
        /**
@@ -649,21 +682,37 @@ class MediaHandler {
         **/
        void dirInfo( filesystem::DirContent & retlist,
                       const Pathname & dirname, bool dots = true ) const;
+
+        /**
+         * check if a file exists
+         *
+         * Asserted that url is a file and not a dir.
+         *
+         * \throws MediaException
+         *
+         **/
+        bool doesFileExist( const Pathname & filename ) const;
+
+        /**
+         * Check if the media has one more device available for attach(true).
+         */
+        virtual bool hasMoreDevices();
+
+        /**
+         * Fill in a vector of detected ejectable devices and the index of the
+         * currently attached device within the vector. The contents of the vector
+         * are the device names (/dev/cdrom and such).
+         *
+         * \param devices  vector to load with the device names
+         * \param index    index of the currently used device in the devices vector
+         */
+        virtual void
+        getDetectedDevices(std::vector<std::string> & devices,
+                           unsigned int & index) const;
 };
 
 ///////////////////////////////////////////////////////////////////
 
-#define        MEDIA_HANDLER_API                                               \
-    protected:                                                         \
-       virtual void attachTo (bool next = false);                      \
-       virtual void releaseFrom( bool eject );                 \
-       virtual void getFile( const Pathname & filename ) const;        \
-       virtual void getDir( const Pathname & dirname, bool recurse_r ) const;  \
-        virtual void getDirInfo( std::list<std::string> & retlist,     \
-                                   const Pathname & dirname, bool dots = true ) const; \
-        virtual void getDirInfo( filesystem::DirContent & retlist,     \
-                                   const Pathname & dirname, bool dots = true ) const;
-
   } // namespace media
 } // namespace zypp