From e7dd10d434c1f4ad6c22dc4ecaf6fe3532bc7e32 Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Tue, 26 Sep 2006 10:58:44 +0000 Subject: [PATCH] - Fixed to include the mount cmd output in MediaMountException (#159596) --- zypp/media/MediaCD.cc | 21 ++++++++++++++++++++- zypp/media/MediaException.cc | 8 ++++++-- zypp/media/MediaException.h | 19 ++++++++++++++++++- zypp/media/MediaISO.cc | 5 +++-- zypp/media/Mount.cc | 8 ++++++-- 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/zypp/media/MediaCD.cc b/zypp/media/MediaCD.cc index be5ddfa..b7db9b8 100644 --- a/zypp/media/MediaCD.cc +++ b/zypp/media/MediaCD.cc @@ -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; } diff --git a/zypp/media/MediaException.cc b/zypp/media/MediaException.cc index 2697c08..0a019fa 100644 --- a/zypp/media/MediaException.cc +++ b/zypp/media/MediaException.cc @@ -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 diff --git a/zypp/media/MediaException.h b/zypp/media/MediaException.h index fafa4f5..e620cdd 100644 --- a/zypp/media/MediaException.h +++ b/zypp/media/MediaException.h @@ -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 diff --git a/zypp/media/MediaISO.cc b/zypp/media/MediaISO.cc index 5fdd36d..f4b0d1e 100644 --- a/zypp/media/MediaISO.cc +++ b/zypp/media/MediaISO.cc @@ -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 )); } } diff --git a/zypp/media/Mount.cc b/zypp/media/Mount.cc index 67dc8f8..804bb3e 100644 --- a/zypp/media/Mount.cc +++ b/zypp/media/Mount.cc @@ -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; } -- 2.7.4