Imported Upstream version 15.19.0
[platform/upstream/libzypp.git] / zypp / media / MediaHandler.h
index 295127b..52fd9a8 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
@@ -208,9 +216,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.
@@ -256,15 +266,24 @@ class MediaHandler {
        /**
         * Check actual mediaSource attachment against the current
         * mount table of the system. Used to implement isAttached().
-        * \param aDevice If to check only against devices in the
-        *                mount table or only against other mounted
-        *                sources (nfs, cifs, loop mounted file).
-        * \param fsType  If to use the filesystem type from the
-        *                mount table or not (nfs, smb and cifs only).
+        * \param matchMountFs If to use the filesystem type from the
+        *        mount table (nfs, smb and cifs) or from mediaSource
+        *        while compare of a mount entry with mediaSource.
         * \return true, if the media appears in the mount table.
         */
-       bool             checkAttached(bool aDevice,
-                                      bool fsType=false) const;
+       bool             checkAttached(bool matchMountFs) const;
+
+       /**
+        * Call to this function will try to release all media matching
+        * the currenlty attached media source, that it is able to find
+        * in the mount table. This means also foreign (user) mounts!
+        * \param matchMountFs If to use the filesystem type from the
+        *        mount table (nfs, smb and cifs) or from mediaSource
+        *        while compare of a mount entry with mediaSource.
+        */
+       void             forceRelaseAllMedia(bool matchMountFs);
+       void             forceRelaseAllMedia(const MediaSourceRef &ref,
+                                            bool matchMountFs);
 
     protected:
 
@@ -312,11 +331,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)
@@ -324,7 +344,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.
@@ -402,6 +422,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:
 
         /**
@@ -490,7 +520,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,
@@ -526,12 +556,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
@@ -610,6 +639,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:
 
        /**
@@ -642,21 +681,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