_handler = new MediaCurl (url,preferred_attach_point);
else
{
- ERR << "Error::E_bad_media_type opening " << url << endl;
ZYPP_THROW(MediaUnsupportedUrlSchemeException(url));
}
void MediaAccess::attach (bool next)
{
if ( !_handler ) {
- INT << "Error::E_media_not_open" << endl;
- ZYPP_THROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException("attach"));
}
_handler->attach(next);
}
MediaAccess::disconnect()
{
if ( !_handler )
- ZYPP_THROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException("disconnect"));
_handler->disconnect();
}
ZYPP_THROW(MediaFileNotFoundException(url(), filename));
if ( !_handler ) {
- INT << "Error::E_media_not_open" << " on provideFile(" << filename << ")" << endl;
- ZYPP_THROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException("provideFile(" + filename.asString() + ")"));
}
_handler->provideFile( filename );
MediaAccess::provideDir( const Pathname & dirname ) const
{
if ( !_handler ) {
- INT << "Error::E_media_not_open" << " on provideDir(" << dirname << ")" << endl;
- ZYPP_THROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException("provideDir(" + dirname.asString() + ")"));
}
_handler->provideDir( dirname );
MediaAccess::provideDirTree( const Pathname & dirname ) const
{
if ( !_handler ) {
- INT << "Error::E_media_not_open" << " on provideDirTree(" << dirname << ")" << endl;
- ZYPP_THROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException("provideDirTree(" + dirname.asString() + ")"));
}
_handler->provideDirTree( dirname );
retlist.clear();
if ( !_handler ) {
- INT << "Error::E_media_not_open" << " on dirInfo(" << dirname << ")" << endl;
- ZYPP_THROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException("dirInfo(" + dirname.asString() + ")"));
}
_handler->dirInfo( retlist, dirname, dots );
retlist.clear();
if ( !_handler ) {
- INT << "Error::E_media_not_open" << " on dirInfo(" << dirname << ")" << endl;
- ZYPP_THROW(MediaNotOpenException());
+ ZYPP_THROW(MediaNotOpenException("dirInfo(" + dirname.asString() + ")"));
}
_handler->dirInfo( retlist, dirname, dots );
#include "zypp/ExternalProgram.h"
#include "zypp/media/Mount.h"
#include "zypp/media/MediaCD.h"
+#include "zypp/Url.h"
#include <cstring> // strerror
void MediaCD::attachTo(bool next)
{
Mount mount;
- const char *mountpoint = attachPoint().asString().c_str();
+ string mountpoint = attachPoint().asString();
bool mountsucceeded = false;
int count = 0;
; ++fsit)
{
try {
- mount.mount (*it, mountpoint, *fsit, options);
+ mount.mount (*it, mountpoint.c_str(), *fsit, options);
_mounteddevice = *it;
_lastdev = count;
mountsucceeded = true;
{
_mounteddevice.erase();
_lastdev = -1;
- // FIXME not suitable for MediaMountExeption, as device cannot be
- // specified here
- // errors might be different as well
- ZYPP_THROW(MediaException("Error::E_mount_failed"));
+ ZYPP_THROW(MediaMountException(_url.toString(), mountpoint, "Mounting media failed"));
}
DBG << _lastdev << " " << count << endl;
}
std::ostream & MediaNotOpenException::dumpOn( std::ostream & str ) const
{
- return str << "Media not opened." << endl;
+ return str << "Media not opened while performing action " << _action << endl;
}
std::ostream & MediaFileNotFoundException::dumpOn( std::ostream & str) const
return str << "Media not attached: " << _url << endl;
}
+ std::ostream & MediaBadAttachPointException::dumpOn( std::ostream & str) const
+ {
+ return str << "Bad media attach point: " << _url << endl;
+ }
+
std::ostream & MediaSystemException::dumpOn( std::ostream & str) const
{
return str << "System exception: " << _message
class MediaNotOpenException : public MediaException
{
public:
- MediaNotOpenException()
+ MediaNotOpenException(const std::string & action_r)
: MediaException()
+ , _action(action_r)
{}
virtual ~MediaNotOpenException() throw() {};
protected:
virtual std::ostream & dumpOn( std::ostream & str ) const;
private:
+ std::string _action;
};
class MediaFileNotFoundException : public MediaException
std::string _url;
};
+ class MediaBadAttachPointException : public MediaException
+ {
+ public:
+ MediaBadAttachPointException(const Url & url_r)
+ : MediaException()
+ , _url(url_r.toString())
+ {}
+ virtual ~MediaBadAttachPointException() throw() {};
+ protected:
+ virtual std::ostream & dumpOn( std::ostream & str ) const;
+ private:
+ std::string _url;
+ };
+
class MediaSystemException : public MediaException
{
public:
return;
if ( _attachPoint.empty() ) {
- ERR << "Error::E_bad_attachpoint" << endl;
- ZYPP_THROW( MediaException("Error::E_bad_attachpoint") );
+ ERR << "Bad Attachpoint" << endl;
+ ZYPP_THROW( MediaBadAttachPointException(url()));
}
- try {
- attachTo( next ); // pass to concrete handler
- }
- catch (const MediaException & excpt_r)
- {
- WAR << "Attach failed: " << excpt_r << " " << *this << endl;
- ZYPP_RETHROW(excpt_r);
- }
+ attachTo( next ); // pass to concrete handler
_isAttached = true;
MIL << "Attached: " << *this << endl;
}
if ( !_isAttached )
return;
- try {
- disconnectFrom(); // pass to concrete handler
- }
- catch (const MediaException & excpt_r)
- {
- WAR << "Disconnect failed: " << excpt_r << " " << *this << endl;
- ZYPP_RETHROW(excpt_r);
- }
+ disconnectFrom(); // pass to concrete handler
MIL << "Disconnected: " << *this << endl;
}
return;
}
- try {
- releaseFrom( eject ); // pass to concrete handler
- }
- catch (const MediaException & excpt_r)
- {
- WAR << "Release failed: " << excpt_r << " " << *this << endl;
- ZYPP_RETHROW(excpt_r);
- }
+ releaseFrom( eject ); // pass to concrete handler
_isAttached = false;
MIL << "Released: " << *this << endl;
}
Pathname targetFilename ) const
{
if ( !_isAttached ) {
- INT << "Error::E_not_attached" << " on provideFileCopy(" << srcFilename
+ INT << "Media not_attached on provideFileCopy(" << srcFilename
<< "," << targetFilename << ")" << endl;
ZYPP_THROW(MediaNotAttachedException(url()));
}
- try {
- getFileCopy( srcFilename, targetFilename ); // pass to concrete handler
- }
- catch (const MediaException & excpt_r)
- {
- WAR << "provideFileCopy(" << srcFilename << "," << targetFilename << "): " << excpt_r << endl;
- ZYPP_RETHROW(excpt_r);
- }
+ getFileCopy( srcFilename, targetFilename ); // pass to concrete handler
DBG << "provideFileCopy(" << srcFilename << "," << targetFilename << ")" << endl;
}
ZYPP_THROW(MediaNotAttachedException(url()));
}
- try {
- getFile( filename ); // pass to concrete handler
- }
- catch (const MediaException & excpt_r)
- {
- WAR << "provideFile(" << filename << "): " << excpt_r << endl;
- ZYPP_RETHROW(excpt_r);
- }
+ getFile( filename ); // pass to concrete handler
DBG << "provideFile(" << filename << ")" << endl;
}
INT << "Error: Not attached on provideDir(" << dirname << ")" << endl;
ZYPP_THROW(MediaNotAttachedException(url()));
}
- try {
- getDir( dirname, /*recursive*/false ); // pass to concrete handler
- }
- catch (const MediaException & excpt_r)
- {
- WAR << "provideDir(" << dirname << "): " << excpt_r << endl;
- ZYPP_RETHROW(excpt_r);
- }
+
+ getDir( dirname, /*recursive*/false ); // pass to concrete handler
MIL << "provideDir(" << dirname << ")" << endl;
}
ZYPP_THROW(MediaNotAttachedException(url()));
}
- try {
- getDir( dirname, /*recursive*/true ); // pass to concrete handler
- }
- catch (const MediaException & excpt_r)
- {
- WAR << "provideDirTree(" << dirname << "): " << excpt_r << endl;
- ZYPP_RETHROW(excpt_r);
- }
-
+ getDir( dirname, /*recursive*/true ); // pass to concrete handler
MIL << "provideDirTree(" << dirname << ")" << endl;
}
ZYPP_THROW(MediaNotAttachedException(url()));
}
- try {
- getDirInfo( retlist, dirname, dots ); // pass to concrete handler
- }
- catch (const MediaException & excpt_r)
- {
- WAR << "dirInfo(" << dirname << "): " << excpt_r << endl;
- ZYPP_RETHROW(excpt_r);
- }
+ getDirInfo( retlist, dirname, dots ); // pass to concrete handler
MIL << "dirInfo(" << dirname << ")" << endl;
}
ZYPP_THROW(MediaNotAttachedException(url()));
}
- try {
- getDirInfo( retlist, dirname, dots ); // pass to concrete handler
- }
- catch (const MediaException & excpt_r)
- {
- WAR << "dirInfo(" << dirname << "): " << excpt_r << endl;
- ZYPP_RETHROW(excpt_r);
- }
+ getDirInfo( retlist, dirname, dots ); // pass to concrete handler
MIL << "dirInfo(" << dirname << ")" << endl;
}
retlist.clear();
filesystem::DirContent content;
- try {
- getDirectoryYast( content, dirname, dots );
- }
- catch (const MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
+ getDirectoryYast( content, dirname, dots );
// convert to std::list<std::string>
for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
// look for directory.yast
Pathname dirFile = dirname + "directory.yast";
- try {
- getFile( dirFile );
- }
- catch (const MediaException & excpt_r)
- {
- ERR << "provideFile(" << dirFile << "): " << excpt_r << endl;
- ZYPP_RETHROW(excpt_r);
- }
+ getFile( dirFile );
DBG << "provideFile(" << dirFile << "): " << "OK" << endl;
// using directory.yast
void MediaHandler::getFileCopy ( const Pathname & srcFilename, const Pathname & targetFilename ) const
{
- try {
- getFile(srcFilename);
- }
- catch (const MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
+ getFile(srcFilename);
if ( copy( localPath( srcFilename ), targetFilename ) != 0 ) {
ZYPP_THROW(MediaWriteException(targetFilename));
if ( process == NULL )
{
- ZYPP_THROW(MediaMountException(source, target, "Error::E_mount_failed"));
+ ZYPP_THROW(MediaMountException(source, target, "Mounting media failed"));
}
string value;
if ( value.find ( "is already mounted on" ) != string::npos )
{
- err = "Error::E_already_mounted";
+ err = "Media already mounted";
}
else if ( value.find ( "ermission denied" ) != string::npos )
{
- err = "Error::E_no_permission";
+ err = "Permission denied";
}
else if ( value.find ( "wrong fs type" ) != string::npos )
{
- err = "Error::E_invalid_filesystem";
+ err = "Invalid filesystem on media";
}
output = process->receiveLine();
}
else if ( status != 0 && err == "" )
{
- err = "Error::E_mount_failed";
+ err = "Mounting media failed";
}
if ( err != "" ) {
if ( value.find ( "device is busy" ) != string::npos )
{
- err = "Error::E_busy";
+ err = "Device is busy";
}
output = process->receiveLine();
}
else if ( status != 0 && err == "" )
{
- err = "Error::E_umount_failed";
+ err = "Unmounting media failed";
}
if ( err != "") {