- Fixed to include the mount cmd output in MediaMountException (#159596)
authorMarius Tomaschewski <mt@suse.de>
Tue, 26 Sep 2006 10:58:44 +0000 (10:58 +0000)
committerMarius Tomaschewski <mt@suse.de>
Tue, 26 Sep 2006 10:58:44 +0000 (10:58 +0000)
zypp/media/MediaCD.cc
zypp/media/MediaException.cc
zypp/media/MediaException.h
zypp/media/MediaISO.cc
zypp/media/Mount.cc

index be5ddfa..b7db9b8 100644 (file)
@@ -464,6 +464,7 @@ namespace zypp {
       string mountpoint = attachPoint().asString();
       bool mountsucceeded = false;
       int count = 0;
+      MediaMountException merr;
 
       string options = _url.getQueryParam("mountoptions");
       if (options.empty())
@@ -594,6 +595,12 @@ namespace zypp {
              ));
            }
          }
+         catch (const MediaMountException &e)
+         {
+           merr = e;
+           removeAttachPoint();
+           ZYPP_CAUGHT(e);
+         }
          catch (const MediaException & excpt_r)
          {
            removeAttachPoint();
@@ -605,7 +612,19 @@ namespace zypp {
       if (!mountsucceeded)
       {
        _lastdev = -1;
-        ZYPP_THROW(MediaMountException(_url.asString(), mountpoint, "Mounting media failed"));
+
+       if( !merr.mountOutput().empty())
+       {
+         ZYPP_THROW(MediaMountException(merr.mountError(),
+                                        _url.asString(),
+                                        mountpoint,
+                                        merr.mountOutput()));
+       }
+       else
+       {
+         ZYPP_THROW(MediaMountException("Mounting media failed",
+                                        _url.asString(), mountpoint));
+       }
       }
       DBG << _lastdev << " " << count << endl;
     }
index 2697c08..0a019fa 100644 (file)
@@ -25,8 +25,12 @@ namespace zypp
 
     std::ostream & MediaMountException::dumpOn( std::ostream & str ) const
     {
-      return str << "Failed to mount " << _source << " on " << _target
-       << " : " << _error << endl;
+      str << "Failed to mount " << _source << " on " << _target;
+      if( !_cmdout.empty())
+       str << ": " << _error << " (" << _cmdout << ")" << endl;
+      else
+       str << ": " << _error << endl;
+      return str;
     }
 
     std::ostream & MediaUnmountException::dumpOn( std::ostream & str ) const
index fafa4f5..e620cdd 100644 (file)
@@ -52,25 +52,42 @@ namespace zypp
     class MediaMountException : public MediaException
     {
     public:
+      MediaMountException()
+      : MediaException( "Media Mount Exception" )
+      {}
+
       /** Ctor taking message.
        * Use \ref ZYPP_THROW to throw exceptions.
       */
       MediaMountException( const std::string & error_r,
                           const std::string & source_r,
-                          const std::string & target_r )
+                          const std::string & target_r,
+                          const std::string & cmdout_r="")
       : MediaException()
       , _error(error_r)
       , _source(source_r)
       , _target(target_r)
+      , _cmdout(cmdout_r)
       {}
       /** Dtor. */
       virtual ~MediaMountException() throw() {};
+
+      const std::string & mountError() const
+      { return _error;  }
+      const std::string & mountSource() const
+      { return _source; }
+      const std::string & mountTarget() const
+      { return _target; }
+      const std::string & mountOutput() const
+      { return _cmdout; }
+
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
       std::string _error;
       std::string _source;
       std::string _target;
+      std::string _cmdout;
     };
 
     class MediaUnmountException : public MediaException
index 5fdd36d..f4b0d1e 100644 (file)
@@ -233,8 +233,9 @@ namespace zypp
         {
           ZYPP_CAUGHT(excpt_r);
         }
-        ZYPP_THROW(MediaMountException(isofile.asString(), mountpoint,
-          "Unable to verify that the media was mounted"
+        ZYPP_THROW(MediaMountException(
+          "Unable to verify that the media was mounted",
+          isofile.asString(), mountpoint
         ));
       }
     }
index 67dc8f8..804bb3e 100644 (file)
@@ -73,7 +73,7 @@ void Mount::mount ( const string& source,
 
     if ( process == NULL )
     {
-      ZYPP_THROW(MediaMountException(source, target, "Mounting media failed"));
+      ZYPP_THROW(MediaMountException("Mounting media failed", source, target));
     }
 
     string value;
@@ -119,6 +119,10 @@ void Mount::mount ( const string& source,
            {
                err = "Nfs path is not a directory";
            }
+           else
+           {
+              err = "Unable to find directory on the media";
+           }
        }
 
        output = process->receiveLine();
@@ -138,7 +142,7 @@ void Mount::mount ( const string& source,
 
     if ( err != "" ) {
       WAR << "mount " << source << " " << target << ": " << err << endl;
-      ZYPP_THROW(MediaMountException(source, target, err));
+      ZYPP_THROW(MediaMountException(err, source, target, value));
     } else {
       MIL << "mounted " << source << " " << target << endl;
     }