improved media exceptions handling
authorJiri Srain <jsrain@suse.cz>
Mon, 12 Dec 2005 17:20:41 +0000 (17:20 +0000)
committerJiri Srain <jsrain@suse.cz>
Mon, 12 Dec 2005 17:20:41 +0000 (17:20 +0000)
zypp/media/Makefile.am
zypp/media/MediaAccess.cc
zypp/media/MediaAccess.h
zypp/media/MediaCurl.cc
zypp/media/MediaException.cc [new file with mode: 0644]
zypp/media/MediaException.h
zypp/media/MediaHandler.cc
zypp/media/MediaHandler.h

index d380a94..a4e02bd 100644 (file)
@@ -11,21 +11,23 @@ include_HEADERS =           \
        MediaException.h        \
        MediaAccess.h           \
        MediaHandler.h          \
-       Mount.h
-
-#      MediaCurl.h
+       Mount.h                 \
+       MediaCurl.h
 
+#      MediaNFS.h              
 
 noinst_LTLIBRARIES =   lib@PACKAGE@_media.la
 
 ## ##################################################
 
 lib@PACKAGE@_media_la_SOURCES = \
+       MediaException.cc       \
        MediaAccess.cc          \
        MediaHandler.cc         \
-       Mount.cc
+       Mount.cc                \
+       MediaCurl.cc
 
-#      MediaCurl.cc
+#      MediaNFS.cc             
 
 lib@PACKAGE@_media_la_LIBADD = -lcurl
 
index eb0675e..e9e9e30 100644 (file)
 #include "zypp/media/MediaCD.h"
 #include "zypp/media/MediaDIR.h"
 #include "zypp/media/MediaDISK.h"
-#include "zypp/media/MediaNFS.h"
 #include "zypp/media/MediaSMB.h"
 #include "zypp/media/MediaCIFS.h"
+#include "zypp/media/MediaNFS.h"
 */
-//#include "zypp/media/MediaCurl.h"
+#include "zypp/media/MediaCurl.h"
 
 using namespace std;
 
@@ -53,10 +53,7 @@ MediaAccess::MediaAccess ()
 // destructor
 MediaAccess::~MediaAccess()
 {
-#warning FIXME uncomment
-#if 0
   DBG << *this << endl;
-#endif
   close(); // !!! make sure handler gets properly deleted.
 }
 
@@ -64,15 +61,14 @@ MediaAccess::~MediaAccess()
 void
 MediaAccess::open (const Url& url, const Pathname & preferred_attach_point)
 {
-#warning FIXME uncomment once media backends get ready
-#if 0
     if(!url.isValid()) {
-        ERR << Error::E_bad_url << " opening " << url << endl;
-       return Error::E_bad_url;
+        ZYPP_DOTHROW(MediaBadUrlException(url));
     }
 
     close();
 
+#warning FIXME uncomment once media backends get ready
+#if 0
     switch ( url.protocol() ) {
       case Url::cd:
       case Url::dvd:
@@ -115,17 +111,14 @@ MediaAccess::open (const Url& url, const Pathname & preferred_attach_point)
 }
 
 // Type of media if open, otherwise NONE.
-#warning FIXME uncomment once real Url class is implemented
-#if 0
-Url::Protocol
+std::string
 MediaAccess::protocol() const
 {
   if ( !_handler )
-    return Url::unknown;
+    return "unknown";
 
   return _handler->protocol();
 }
-#endif
 
 ///////////////////////////////////////////////////////////////////
 //
@@ -155,16 +148,11 @@ MediaAccess::close ()
     }
     catch (const MediaException & excpt_r)
     {
-#warning FIXME uncomment, rethrow
-#if 0
-      WAR << "Close: " << *this << " (" << err << ")" << endl;
+      ZYPP_CAUGHT(excpt_r);
+      WAR << "Close: " << *this << " (" << excpt_r << ")" << endl;
       ZYPP_RETHROW(excpt_r);
-#endif
     }
-#warning FIXME uncomment
-#if 0
-    MIL << "Close: " << *this << " (" << err << ")" << endl;
-#endif
+    MIL << "Close: " << *this << " (OK)" << endl;
     delete _handler;
     _handler = 0;
   }
@@ -175,8 +163,8 @@ MediaAccess::close ()
 void MediaAccess::attach (bool next)
 {
   if ( !_handler ) {
-    INT << "Error::E_not_open" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_open");
+    INT << "Error::E_media_not_open" << endl;
+    ZYPP_DOTHROW(MediaNotOpenException());
   }
   _handler->attach(next);
 }
@@ -214,7 +202,7 @@ void
 MediaAccess::disconnect()
 {
   if ( !_handler )
-    ZYPP_THROW( MediaException, "Error::E_not_open");
+    ZYPP_DOTHROW(MediaNotOpenException());
 
   _handler->disconnect();
 }
@@ -244,11 +232,11 @@ MediaAccess::provideFile( const Pathname & filename, bool cached, bool checkonly
   }
 
   if(checkonly)
-    ZYPP_THROW( MediaException, "Error::E_error");
+    ZYPP_DOTHROW(MediaFileNotFoundException(url(), filename));
 
   if ( !_handler ) {
-    INT << "Error::E_not_open" << " on provideFile(" << filename << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_open");
+    INT << "Error::E_media_not_open" << " on provideFile(" << filename << ")" << endl;
+    ZYPP_DOTHROW(MediaNotOpenException());
   }
 
   _handler->provideFile( filename );
@@ -271,8 +259,8 @@ void
 MediaAccess::provideDir( const Pathname & dirname ) const
 {
   if ( !_handler ) {
-    INT << "Error::E_not_open" << " on provideDir(" << dirname << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_open");
+    INT << "Error::E_media_not_open" << " on provideDir(" << dirname << ")" << endl;
+    ZYPP_DOTHROW(MediaNotOpenException());
   }
 
   _handler->provideDir( dirname );
@@ -282,8 +270,8 @@ void
 MediaAccess::provideDirTree( const Pathname & dirname ) const
 {
   if ( !_handler ) {
-    INT << "Error::E_not_open" << " on provideDirTree(" << dirname << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_open");
+    INT << "Error::E_media_not_open" << " on provideDirTree(" << dirname << ")" << endl;
+    ZYPP_DOTHROW(MediaNotOpenException());
   }
 
   _handler->provideDirTree( dirname );
@@ -314,8 +302,8 @@ MediaAccess::dirInfo( list<string> & retlist, const Pathname & dirname, bool dot
   retlist.clear();
 
   if ( !_handler ) {
-    INT << "Error::E_not_open" << " on dirInfo(" << dirname << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_open");
+    INT << "Error::E_media_not_open" << " on dirInfo(" << dirname << ")" << endl;
+    ZYPP_DOTHROW(MediaNotOpenException());
   }
 
   _handler->dirInfo( retlist, dirname, dots );
@@ -328,8 +316,8 @@ MediaAccess::dirInfo( filesystem::DirContent & retlist, const Pathname & dirname
   retlist.clear();
 
   if ( !_handler ) {
-    INT << "Error::E_not_open" << " on dirInfo(" << dirname << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_open");
+    INT << "Error::E_media_not_open" << " on dirInfo(" << dirname << ")" << endl;
+    ZYPP_DOTHROW(MediaNotOpenException());
   }
 
   _handler->dirInfo( retlist, dirname, dots );
@@ -341,11 +329,7 @@ MediaAccess::dumpOn( std::ostream & str ) const
   if ( !_handler )
     return str << "MediaAccess( closed )";
 
-#warning FIXME uncomment once real Url class is implemented
-#if 0
-  string tstr = Url::protocolToString( _handler->protocol() );
-  str << tstr << "(" << *_handler << ")";
-#endif
+  str << _handler->protocol() << "(" << *_handler << ")";
   return str;
 }
 
@@ -353,20 +337,12 @@ void MediaAccess::getFile( const Url &from, const Pathname &to )
 {
   DBG << "From: " << from << endl << "To: " << to << endl;
 
-  Pathname path
-#warning FIXME uncomment once real Url class is implemented
-#if 0
- = from.path()
-#endif
-;
+  Pathname path = from.getPathData();
   Pathname dir = path.dirname();
   string base = path.basename();
 
   Url u = from;
-#warning FIXME uncomment once real Url class is implemented
-#if 0
-  u.setPath( dir.asString() );
-#endif
+  u.setPathData( dir.asString() );
 
   MediaAccess media;
 
@@ -378,12 +354,11 @@ void MediaAccess::getFile( const Url &from, const Pathname &to )
   }
   catch (const MediaException & excpt_r)
   {
-#warning FIXME uncomment, add message into log
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
 }
+    std::ostream & operator<<( std::ostream & str, const MediaAccess & obj )
+    { return obj.dumpOn( str ); }
 
 ///////////////////////////////////////////////////////////////////
   } // namespace media
index 059a6be..46b381b 100644 (file)
 #include "zypp/PathInfo.h"
 
 #include "zypp/media/MediaException.h"
-
-#warning FIXME use real Url class
-// #include "zypp/@Review/Url.h"
-typedef std::string Url;
+#include "zypp/Url.h"
 
 namespace zypp {
   namespace media {
@@ -90,10 +87,7 @@ namespace zypp {
        /**
         * Used Protocol if media is opened, otherwise 'unknown'.
         **/
-#warning FIXME uncomment once real Url class is implemented
-#if 0
-        Url::Protocol protocol() const;
-#endif
+        std::string protocol() const;
 
        /**
         * Url if media is opened, otherwise empty.
@@ -318,6 +312,7 @@ namespace zypp {
        * Currently we can not releaseFile after the media was closed
        * (it's passed to the handler, which is deleted on close).
        *
+       * \throws MediaBadFilenameException
        * \throws MediaException
        **/
       class FileProvider {
@@ -337,7 +332,7 @@ namespace zypp {
            , _local_file( "" )
          {
            if ( _file.empty() ) {
-             ZYPP_THROW( MediaException, "E_bad_filename");
+             ZYPP_DOTHROW(MediaBadFilenameException(_file.asString()));
            } else if ( _media ) {
              try {
                _media->provideFile( _file );
@@ -345,11 +340,9 @@ namespace zypp {
              }
              catch (const MediaException & excpt_r)
               {
+               ZYPP_CAUGHT(excpt_r);
                _media = NULL;
-#warning FIXME rethrow the exception
-#if 0
                ZYPP_RETHROW(excpt_r);
-#endif
              }
            }
          }
@@ -362,6 +355,7 @@ namespace zypp {
              }
              catch (const MediaException &excpt_r)
              {
+               ZYPP_CAUGHT(excpt_r);
                INT << "Exception raised while releasing file" << std::endl;
              }
            }
@@ -387,6 +381,8 @@ namespace zypp {
       };
     };
 
+    std::ostream & operator<<( std::ostream & str, const MediaAccess & obj );
+
 ///////////////////////////////////////////////////////////////////
 
   } // namespace media
index e9c30a7..30f6dbd 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "zypp/base/Logger.h"
 #include "zypp/ExternalProgram.h"
+#include "zypp/base/String.h"
 //#include <y2util/SysConfig.h>
 
 #include "zypp/media/MediaCurl.h"
@@ -101,8 +102,11 @@ void MediaCurl::attachTo (bool next)
   if ( next )
     ZYPP_THROW( MediaException, "Error::E_not_supported_by_media");
 
+#warning FIXME implement check for URL validity
+#if 0
   if ( !_url.isValid() )
     ZYPP_THROW( MediaException, "Error::E_bad_url");
+#endif
 
   _curl = curl_easy_init();
   if ( !_curl ) {
@@ -124,7 +128,7 @@ void MediaCurl::attachTo (bool next)
     ZYPP_THROW( MediaException, "Error::E_curl_setopt_failed");
   }
 
-  if ( _url.protocol() == Url::http ) {
+  if ( _url.getScheme() == "http" ) {
     // follow any Location: header that the server sends as part of
     // an HTTP header (#113275)
     ret = curl_easy_setopt ( _curl, CURLOPT_FOLLOWLOCATION, true );
@@ -141,7 +145,7 @@ void MediaCurl::attachTo (bool next)
 
   // XXX: wasn't that the wrong fix for some problem? this should be
   // removed
-  if ( _url.protocol() == Url::https ) {
+  if ( _url.getScheme() == "https" ) {
     WAR << "Disable certificate verification for https." << endl;
     ret = curl_easy_setopt( _curl, CURLOPT_SSL_VERIFYPEER, 0 );
     if ( ret != 0 ) {
@@ -164,17 +168,17 @@ void MediaCurl::attachTo (bool next)
    If not provided, anonymous FTP identification
    *---------------------------------------------------------------*/
 
-  if ( _url.username().empty() ) {
-    if ( _url.protocol() == Url::ftp ) {
+  if ( _url.getUsername().empty() ) {
+    if ( _url.getScheme() == "ftp" ) {
       string id = "yast2@";
       id += VERSION;
       DBG << "Anonymous FTP identification: '" << id << "'" << endl;
       _userpwd = "anonymous:" + id;
     }
   } else {
-    _userpwd = _url.username();
-    if ( _url.password().size() ) {
-      _userpwd += ":" + _url.password();
+    _userpwd = _url.getUsername();
+    if ( _url.getPassword().size() ) {
+      _userpwd += ":" + _url.getPassword();
     }
   }
 
@@ -194,6 +198,9 @@ void MediaCurl::attachTo (bool next)
    If not provided, /etc/sysconfig/proxy is evaluated
    *---------------------------------------------------------------*/
 
+#warning FIX once I understand how to get this info
+#warning FIXME enable proxy via sysconfig somehow
+#if 0
   _proxy = _url.option( "proxy" );
 
   if ( ! _proxy.empty() ) {
@@ -201,9 +208,6 @@ void MediaCurl::attachTo (bool next)
     if ( ! proxyport.empty() ) {
       _proxy += ":" + proxyport;
     }
-
-#warning FIXME enable proxy via sysconfig somehow
-#if 0
   } else {
 
     SysConfig cfg( "proxy" );
@@ -216,28 +220,28 @@ void MediaCurl::attachTo (bool next)
       for ( unsigned i = 0; i < nope.size(); ++i ) {
        // no proxy: if nope equals host,
        // or is a suffix preceeded by a '.'
-       string::size_type pos = _url.host().find( nope[i] );
+       string::size_type pos = _url.getHost().find( nope[i] );
        if ( pos != string::npos
-            && ( pos + nope[i].size() == _url.host().size() )
-            && ( pos == 0 || _url.host()[pos -1] == '.' ) ) {
-         DBG << "NO_PROXY: " << nope[i] << " matches host " << _url.host() << endl;
+            && ( pos + nope[i].size() == _url.getHost().size() )
+            && ( pos == 0 || _url.getHost()[pos -1] == '.' ) ) {
+         DBG << "NO_PROXY: " << nope[i] << " matches host " << _url.getHost() << endl;
          useproxy = false;
          break;
        }
       }
 
       if ( useproxy ) {
-       if ( _url.protocol() == Url::ftp ) {
+       if ( _url.getScheme() == Url::ftp ) {
          _proxy = cfg.readEntry( "FTP_PROXY" );
-       } else if ( _url.protocol() == Url::http ) {
+       } else if ( _url.getScheme() == Url::http ) {
          _proxy = cfg.readEntry( "HTTP_PROXY" );
-       } else if ( _url.protocol() == Url::https ) {
+       } else if ( _url.getScheme() == Url::https ) {
          _proxy = cfg.readEntry( "HTTPS_PROXY" );
        }
       }
     }
-#endif
   }
+#endif
 
 
   DBG << "Proxy: " << _proxy << endl;
@@ -257,6 +261,9 @@ void MediaCurl::attachTo (bool next)
      If not provided, $HOME/.curlrc is evaluated
      *---------------------------------------------------------------*/
 
+#warning FIXME once I know how to get this info
+#warning FIXME enable proxy via sysconfig somehow
+#if 0
     _proxyuserpwd = _url.option( "proxyuser" );
 
     if ( ! _proxyuserpwd.empty() ) {
@@ -266,16 +273,14 @@ void MediaCurl::attachTo (bool next)
        _proxyuserpwd += ":" + proxypassword;
       }
 
-#warning FIXME enable proxy via sysconfig somehow
-#if 0
     } else {
 
       string curlrcFile = string( getenv("HOME") ) + string( "/.curlrc" );
       SysConfig curlrc( curlrcFile );
       _proxyuserpwd = curlrc.readEntry( "proxy-user" );
 
-#endif
     }
+#endif
 
     _proxyuserpwd = unEscape( _proxyuserpwd );
     ret = curl_easy_setopt( _curl, CURLOPT_PROXYUSERPWD, _proxyuserpwd.c_str() );
@@ -363,13 +368,16 @@ void MediaCurl::getFileCopy( const Pathname & filename , const Pathname & target
 {
     DBG << filename.asString() << endl;
 
+#warning FIXME implement check for URL validity
+#if 0
     if(!_url.isValid())
-      ZYPP_THROW( MediaException, string("Error::E_bad_url") + " " + _url.asString());
+      ZYPP_THROW( MediaException, string("Error::E_bad_url") + " " + _url.toString());
+#endif
 
-    if(_url.host().empty())
+    if(_url.getHost().empty())
       ZYPP_THROW( MediaException, "Error::E_no_host_specified");
 
-    string path = _url.path();
+    string path = _url.getPathName();
     if ( !path.empty() && path != "/" && *path.rbegin() == '/' &&
          filename.absolute() ) {
       // If url has a path with trailing slash, remove the leading slash from
@@ -385,7 +393,7 @@ void MediaCurl::getFileCopy( const Pathname & filename , const Pathname & target
     }
 
     Url url( _url );
-    url.setPath( escapedPath(path) );
+    url.setPathName( escapedPath(path) );
 
     Pathname dest = target.absolutename();
     string destNew = target.asString() + ".new.yast.37456";
@@ -399,14 +407,16 @@ void MediaCurl::getFileCopy( const Pathname & filename , const Pathname & target
       ZYPP_THROW( MediaException, string("Error::E_system") + string(" ") + dest.dirname().asString());
     }
 
-    DBG << "URL: " << url.asString().c_str() << endl;
+    DBG << "URL: " << url.toString().c_str() << endl;
     // Use URL without options (not RFC conform) and without
     // username and passwd (some proxies dislike them in the URL.
     // Curloptions for these were set in attachTo().
     Url curlUrl( url );
     curlUrl.setUsername( "" );
     curlUrl.setPassword( "" );
-    string urlBuffer = curlUrl.asString(true,false,true); // without options
+#warning Check whether the call is correct
+//    string urlBuffer = curlUrl.toString(true,false,true); // without options
+    string urlBuffer = curlUrl.toString(); // without options
 
     CURLcode ret = curl_easy_setopt( _curl, CURLOPT_URL,
                                      urlBuffer.c_str() );
@@ -446,7 +456,7 @@ void MediaCurl::getFileCopy( const Pathname & filename , const Pathname & target
     }
 
     if ( ret != 0 ) {
-      unlink( destNew );
+      filesystem::unlink( destNew );
 
       ERR << "curl error: " << ret << ": " << _curlError << endl;
       std::string err;
@@ -463,12 +473,12 @@ void MediaCurl::getFileCopy( const Pathname & filename , const Pathname & target
                                                   &httpReturnCode );
             if ( infoRet == CURLE_OK ) {
               string msg = "HTTP return code: " +
-                           stringutil::numstring( httpReturnCode ) +
-                           " (URL: " + url.asString() + ")";
+                           str::numstring( httpReturnCode ) +
+                           " (URL: " + url.toString() + ")";
               DBG << msg << endl;
               if ( httpReturnCode == 401 )
              {
-               msg = "URL: " + url.asString();
+               msg = "URL: " + url.toString();
                 err = "Error::E_login_failed";
              }
               else
diff --git a/zypp/media/MediaException.cc b/zypp/media/MediaException.cc
new file mode 100644 (file)
index 0000000..9be0079
--- /dev/null
@@ -0,0 +1,93 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/MediaException.cc
+ *
+*/
+
+#include <string>
+#include <iostream>
+
+#include "zypp/media/MediaException.h"
+
+using namespace std;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  namespace media {
+  /////////////////////////////////////////////////////////////////
+
+    std::ostream & MediaMountException::dumpOn( std::ostream & str ) const
+    {
+      return str << "Failed to mount " << _source << " on " << _target
+       << " : " << _error << endl;
+    }
+
+    std::ostream & MediaUnmountException::dumpOn( std::ostream & str ) const
+    {
+      return str << "Failed to unmount " << _path
+       << " : " << _error << endl;
+    }
+
+    std::ostream & MediaBadFilenameException::dumpOn( std::ostream & str ) const
+    {
+      return str << "Bad file name " << _filename << endl;
+    }
+
+    std::ostream & MediaNotOpenException::dumpOn( std::ostream & str ) const
+    {
+      return str << "Media not opened." << endl;
+    }
+
+    std::ostream & MediaFileNotFoundException::dumpOn( std::ostream & str) const
+    {
+      return str << "File " << _filename
+       << " not found on media: " << _url << endl;
+    }
+
+    std::ostream & MediaWriteException::dumpOn( std::ostream & str) const
+    {
+      return str << "Cannot write file " << _filename << endl;
+    }
+
+    std::ostream & MediaNotAttachedException::dumpOn( std::ostream & str) const
+    {
+      return str << "Media not attached: " << _url << endl;
+    }
+
+    std::ostream & MediaSystemException::dumpOn( std::ostream & str) const
+    {
+      return str << "System exception: " << _message
+       << " on media: " << _url << endl;
+    }
+
+    std::ostream & MediaNotAFileException::dumpOn( std::ostream & str) const
+    {
+      return str << "Path " << _path
+       << " on media: " << _url
+        << " is not a file." << endl;
+    }
+
+    std::ostream & MediaNotADirException::dumpOn( std::ostream & str) const
+    {
+      return str << "Path " << _path
+       << " on media: " << _url
+        << " is not a directory." << endl;
+    }
+
+    std::ostream & MediaBadUrlException::dumpOn( std::ostream & str) const
+    {
+      return str << "Malformed URL: " << _url << endl;
+    }
+
+
+  /////////////////////////////////////////////////////////////////
+  } // namespace media
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
index 6b19ee4..8c7cd20 100644 (file)
@@ -17,6 +17,8 @@
 #include <string>
 
 #include "zypp/base/Exception.h"
+#include "zypp/Pathname.h"
+#include "zypp/Url.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -53,18 +55,20 @@ namespace zypp
       /** Ctor taking message.
        * Use \ref ZYPP_DOTHROW to throw exceptions.
       */
-      MediaMountException( const std::string & msg_r,
+      MediaMountException( const std::string & error_r,
                           const std::string & source_r,
                           const std::string & target_r )
-      : MediaException( msg_r )
+      : MediaException()
+      , _error(error_r)
       , _source(source_r)
       , _target(target_r)
       {}
       /** Dtor. */
       virtual ~MediaMountException() throw() {};
-      std::string source() const { return _source; }
-      std::string target() const { return _target; }
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
+      std::string _error;
       std::string _source;
       std::string _target;
     };
@@ -75,18 +79,160 @@ namespace zypp
       /** Ctor taking message.
        * Use \ref ZYPP_DOTHROW to throw exceptions.
       */
-      MediaUnmountException( const std::string & msg_r,
+      MediaUnmountException( const std::string & error_r,
                             const std::string & path_r )
-      : MediaException( msg_r )
+      : MediaException()
+      , _error(error_r)
       , _path(path_r)
       {}
       /** Dtor. */
       virtual ~MediaUnmountException() throw() {};
-      std::string path() const { return _path; }
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
+      std::string _error;
       std::string _path;
     };
 
+    class MediaBadFilenameException : public MediaException
+    {
+    public:
+      MediaBadFilenameException(const std::string & filename_r)
+      : MediaException()
+      , _filename(filename_r)
+      {}
+      virtual ~MediaBadFilenameException() throw() {};
+      std::string filename() const { return _filename; }
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _filename;
+    };
+
+    class MediaNotOpenException : public MediaException
+    {
+    public:
+      MediaNotOpenException()
+      : MediaException()
+      {}
+      virtual ~MediaNotOpenException() throw() {};
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+    };
+
+    class MediaFileNotFoundException : public MediaException
+    {
+    public:
+      MediaFileNotFoundException(const Url & url_r,
+                                const Pathname & filename_r)
+      : MediaException()
+      , _url(url_r.toString())
+      , _filename(filename_r.asString())
+      {}
+      virtual ~MediaFileNotFoundException() throw() {};
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _url;
+      std::string _filename;
+    };
+
+    class MediaWriteException : public MediaException
+    {
+    public:
+      MediaWriteException(const Pathname & filename_r)
+      : MediaException()
+      , _filename(filename_r.asString())
+      {}
+      virtual ~MediaWriteException() throw() {};
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _filename;
+    };
+
+    class MediaNotAttachedException : public MediaException
+    {
+    public:
+      MediaNotAttachedException(const Url & url_r)
+      : MediaException()
+      , _url(url_r.toString())
+      {}
+      virtual ~MediaNotAttachedException() throw() {};
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _url;
+    };
+
+    class MediaSystemException : public MediaException
+    {
+    public:
+      MediaSystemException(const Url & url_r,
+                          const std::string & message_r)
+      : MediaException()
+      , _url(url_r.toString())
+      , _message(message_r)
+      {}
+      virtual ~MediaSystemException() throw() {};
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _url;
+      std::string _message;
+    };
+
+    class MediaNotAFileException : public MediaException
+    {
+    public:
+      MediaNotAFileException(const Url & url_r,
+                            const Pathname & path_r)
+      : MediaException()
+      , _url(url_r.toString())
+      , _path(path_r.asString())
+      {}
+      virtual ~MediaNotAFileException() throw() {};
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _url;
+      std::string _path;
+    };
+
+    class MediaNotADirException : public MediaException
+    {
+    public:
+      MediaNotADirException(const Url & url_r,
+                           const Pathname & path_r)
+      : MediaException()
+      , _url(url_r.toString())
+      , _path(path_r.asString())
+      {}
+      virtual ~MediaNotADirException() throw() {};
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _url;
+      std::string _path;
+    };
+
+    class MediaBadUrlException : public MediaException
+    {
+    public:
+      MediaBadUrlException(const Url & url_r)
+      : MediaException()
+      , _url(url_r.toString())
+      {}
+      virtual ~MediaBadUrlException() throw() {};
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _url;
+    };
+
+    
+
   /////////////////////////////////////////////////////////////////
   } // namespace media
 } // namespace zypp
index 6760d5f..b4e8f1b 100644 (file)
@@ -162,10 +162,7 @@ void MediaHandler::attach( bool next )
   catch (const MediaException & excpt_r)
   {
     WAR << "Attach failed: " << excpt_r << " " << *this << endl;
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
   _isAttached = true;
   MIL << "Attached: " << *this << endl;
@@ -212,10 +209,7 @@ void MediaHandler::disconnect()
   catch (const MediaException & excpt_r)
   {
     WAR << "Disconnect failed: " << excpt_r << " " << *this << endl;
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
   MIL << "Disconnected: " << *this << endl;
 }
@@ -242,10 +236,7 @@ void MediaHandler::release( bool eject )
   catch (const MediaException & excpt_r)
   {
     WAR << "Release failed: " << excpt_r << " " << *this << endl;
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
   _isAttached = false;
   MIL << "Released: " << *this << endl;
@@ -265,7 +256,7 @@ void MediaHandler::provideFileCopy( Pathname srcFilename,
   if ( !_isAttached ) {
     INT << "Error::E_not_attached" << " on provideFileCopy(" << srcFilename
         << "," << targetFilename << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_attached");
+    ZYPP_DOTHROW(MediaNotAttachedException(url()));
   }
 
   try {
@@ -274,10 +265,7 @@ void MediaHandler::provideFileCopy( Pathname srcFilename,
   catch (const MediaException & excpt_r)
   {
     WAR << "provideFileCopy(" << srcFilename << "," << targetFilename << "): " << excpt_r << endl;
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
   DBG << "provideFileCopy(" << srcFilename << "," << targetFilename  << ")" << endl;
 }
@@ -285,8 +273,8 @@ void MediaHandler::provideFileCopy( Pathname srcFilename,
 void MediaHandler::provideFile( Pathname filename ) const
 {
   if ( !_isAttached ) {
-    INT << "Error::E_not_attached" << " on provideFile(" << filename << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_attached");
+    INT << "Error: Not attached on provideFile(" << filename << ")" << endl;
+    ZYPP_DOTHROW(MediaNotAttachedException(url()));
   }
 
   try {
@@ -295,10 +283,7 @@ void MediaHandler::provideFile( Pathname filename ) const
   catch (const MediaException & excpt_r)
   {
     WAR << "provideFile(" << filename << "): " << excpt_r << endl;
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
   DBG << "provideFile(" << filename << ")" << endl;
 }
@@ -315,8 +300,8 @@ void MediaHandler::provideFile( Pathname filename ) const
 void MediaHandler::provideDir( Pathname dirname ) const
 {
   if ( !_isAttached ) {
-    INT << "Error::E_not_attached" << " on provideDir(" << dirname << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_attached");
+    INT << "Error: Not attached on provideDir(" << dirname << ")" << endl;
+    ZYPP_DOTHROW(MediaNotAttachedException(url()));
   }
   try {
     getDir( dirname, /*recursive*/false ); // pass to concrete handler
@@ -324,10 +309,7 @@ void MediaHandler::provideDir( Pathname dirname ) const
   catch (const MediaException & excpt_r)
   {
     WAR << "provideDir(" << dirname << "): " << excpt_r << endl;
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
   MIL << "provideDir(" << dirname << ")" << endl;
 }
@@ -343,8 +325,8 @@ void MediaHandler::provideDir( Pathname dirname ) const
 void MediaHandler::provideDirTree( Pathname dirname ) const
 {
   if ( !_isAttached ) {
-    INT << "Error::E_not_attached" << " on provideDirTree(" << dirname << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_attached");
+    INT << "Error Not attached on provideDirTree(" << dirname << ")" << endl;
+    ZYPP_DOTHROW(MediaNotAttachedException(url()));
   }
 
   try {
@@ -353,10 +335,7 @@ void MediaHandler::provideDirTree( Pathname dirname ) const
   catch (const MediaException & excpt_r)
   {
     WAR << "provideDirTree(" << dirname << "): " << excpt_r << endl;
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
 
   MIL << "provideDirTree(" << dirname << ")" << endl;
@@ -402,8 +381,8 @@ void MediaHandler::dirInfo( list<string> & retlist,
   retlist.clear();
 
   if ( !_isAttached ) {
-    INT << "Error::E_not_attached" << " on dirInfo(" << dirname << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_attached");
+    INT << "Error: Not attached on dirInfo(" << dirname << ")" << endl;
+    ZYPP_DOTHROW(MediaNotAttachedException(url()));
   }
 
   try {
@@ -412,10 +391,7 @@ void MediaHandler::dirInfo( list<string> & retlist,
   catch (const MediaException & excpt_r)
   {
     WAR << "dirInfo(" << dirname << "): " << excpt_r << endl;
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
   MIL << "dirInfo(" << dirname << ")" << endl;
 }
@@ -434,8 +410,8 @@ void MediaHandler::dirInfo( filesystem::DirContent & retlist,
   retlist.clear();
 
   if ( !_isAttached ) {
-    INT << "Error::E_not_attached" << " on dirInfo(" << dirname << ")" << endl;
-    ZYPP_THROW( MediaException, "Error::E_not_attached");
+    INT << "Error: Not attached on dirInfo(" << dirname << ")" << endl;
+    ZYPP_DOTHROW(MediaNotAttachedException(url()));
   }
 
   try {
@@ -444,10 +420,7 @@ void MediaHandler::dirInfo( filesystem::DirContent & retlist,
   catch (const MediaException & excpt_r)
   {
     WAR << "dirInfo(" << dirname << "): " << excpt_r << endl;
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
   MIL << "dirInfo(" << dirname << ")" << endl;
 }
@@ -469,10 +442,7 @@ void MediaHandler::getDirectoryYast( std::list<std::string> & retlist,
   }
   catch (const MediaException & excpt_r)
   {
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
 
   // convert to std::list<std::string>
@@ -499,11 +469,8 @@ void MediaHandler::getDirectoryYast( filesystem::DirContent & retlist,
   }
   catch (const MediaException & excpt_r)
   {
-#warning FIXME rethrow
-#if 0
     ERR << "provideFile(" << dirFile << "): " << excpt_r << endl;
     ZYPP_RETHROW(excpt_r);
-#endif
   }
   DBG << "provideFile(" << dirFile << "): " << "OK" << endl;
 
@@ -511,7 +478,8 @@ void MediaHandler::getDirectoryYast( filesystem::DirContent & retlist,
   ifstream dir( localPath( dirFile ).asString().c_str() );
   if ( dir.fail() ) {
     ERR << "Unable to load '" << localPath( dirFile ) << "'" << endl;
-    ZYPP_THROW( MediaException, "Error::E_system");
+    ZYPP_DOTHROW(MediaSystemException(url(),
+      "Unable to load '" + localPath( dirFile ).asString() + "'"));
   }
 
   string line;
@@ -567,9 +535,9 @@ void MediaHandler::getFile( const Pathname & filename ) const
     }
 
     if (info.isExist())
-      ZYPP_THROW( MediaException, "Error::E_not_a_file");
+      ZYPP_DOTHROW(MediaNotAFileException(url(), localPath(filename)));
     else
-      ZYPP_THROW( MediaException, "Error::E_file_not_found");
+      ZYPP_DOTHROW(MediaFileNotFoundException(url(), filename));
 }
 
 
@@ -580,14 +548,11 @@ void MediaHandler::getFileCopy ( const Pathname & srcFilename, const Pathname &
   }
   catch (const MediaException & excpt_r)
   {
-#warning FIXME rethrow
-#if 0
     ZYPP_RETHROW(excpt_r);
-#endif
   }
 
   if ( copy( localPath( srcFilename ), targetFilename ) != 0 ) {
-    ZYPP_THROW( MediaException, "Error::E_write_error");
+    ZYPP_DOTHROW(MediaWriteException(targetFilename));
   }
 }
 
@@ -610,9 +575,9 @@ void MediaHandler::getDir( const Pathname & dirname, bool recurse_r ) const
   }
 
   if (info.isExist())
-    ZYPP_THROW( MediaException, "Error::E_not_a_file");
+    ZYPP_DOTHROW(MediaNotADirException(url(), localPath(dirname)));
   else
-    ZYPP_THROW( MediaException, "Error::E_file_not_found");
+    ZYPP_DOTHROW(MediaFileNotFoundException(url(), dirname));
 }
 
 ///////////////////////////////////////////////////////////////////
@@ -629,7 +594,7 @@ void MediaHandler::getDirInfo( std::list<std::string> & retlist,
 {
   PathInfo info( localPath( dirname ) );
   if( ! info.isDir() ) {
-    ZYPP_THROW( MediaException, "Error::E_not_a_directory");
+    ZYPP_DOTHROW(MediaNotADirException(url(), localPath(dirname)));
   }
 
 #if NONREMOTE_DIRECTORY_YAST
@@ -644,7 +609,7 @@ void MediaHandler::getDirInfo( std::list<std::string> & retlist,
   // readdir
     int res = readdir( retlist, info.path(), dots );
   if ( res )
-    ZYPP_THROW( MediaException, "Error::E_system");
+    ZYPP_DOTHROW(MediaSystemException(url(), "readdir failed"));
 
 #if NONREMOTE_DIRECTORY_YAST
   }
@@ -667,7 +632,7 @@ void MediaHandler::getDirInfo( filesystem::DirContent & retlist,
 {
   PathInfo info( localPath( dirname ) );
   if( ! info.isDir() ) {
-    ZYPP_THROW( MediaException, "Error::E_not_a_directory");
+    ZYPP_DOTHROW(MediaNotADirException(url(), localPath(dirname)));
   }
 
 #if NONREMOTE_DIRECTORY_YAST
@@ -682,7 +647,7 @@ void MediaHandler::getDirInfo( filesystem::DirContent & retlist,
   // readdir
   int res = readdir( retlist, info.path(), dots );
   if ( res )
-    ZYPP_THROW( MediaException, "Error::E_system");
+    ZYPP_DOTHROW(MediaSystemException(url(), "readdir failed"));
 #if NONREMOTE_DIRECTORY_YAST
   }
 #endif
index b8487da..8d44753 100644 (file)
@@ -19,9 +19,7 @@
 #include "zypp/Pathname.h"
 #include "zypp/PathInfo.h"
 
-#warning FIXME use real Url class
-// #include "zypp/@Review/Url.h"
-typedef std::string Url;
+#include "zypp/Url.h"
 
 #include "zypp/media/MediaAccess.h"
 
@@ -286,10 +284,7 @@ class MediaHandler {
         /**
         * Protocol hint for MediaAccess.
         **/
-#warning FIXME uncomment once real Url class is implemented
-#if 0
-        Url::Protocol protocol() const { return _url.protocol(); }
-#endif
+        std::string protocol() const { return _url.getScheme(); }
 
        /**
         * Url used.