perform some checks before adding a new operation to the list. made

* include/GParted_Core.h,
  src/GParted_Core.cc,
  src/Win_GParted.cc: perform some checks before adding a new
  operation to the list.
* src/Partition.cc: made get_length() a bit safer
This commit is contained in:
Bart Hakvoort 2006-07-20 19:14:44 +00:00
parent 7f265770eb
commit dc883ee652
5 changed files with 67 additions and 25 deletions

View File

@ -1,3 +1,11 @@
2006-07-20 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/GParted_Core.h,
src/GParted_Core.cc,
src/Win_GParted.cc: perform some checks before adding a new
operation to the list.
* src/Partition.cc: made get_length() a bit safer
2006-07-19 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/Dialog_Progress.cc: added FIXME

View File

@ -38,7 +38,7 @@ public:
void set_user_devices( const std::vector<Glib::ustring> & user_devices ) ;
void set_devices( std::vector<Device> & devices ) ;
bool snap_to_cylinder( const Device & device, Partition & partition ) ;
bool snap_to_cylinder( const Device & device, Partition & partition, Glib::ustring & error ) ;
bool apply_operation_to_disk( Operation * operation );
bool set_disklabel( const Glib::ustring & device_path, const Glib::ustring & disklabel ) ;

View File

@ -229,7 +229,7 @@ void GParted_Core::set_devices( std::vector<Device> & devices )
fstab_info .clear() ;
}
bool GParted_Core::snap_to_cylinder( const Device & device, Partition & partition )
bool GParted_Core::snap_to_cylinder( const Device & device, Partition & partition, Glib::ustring & error )
{
if ( ! partition .strict )
{
@ -256,11 +256,26 @@ bool GParted_Core::snap_to_cylinder( const Device & device, Partition & partitio
if ( partition .sector_end > device .length )
partition .sector_end = device .length -1 ;
//ok, do some basic checks on the partition..
if ( partition .get_length() <= 0 )
{
error = String::ucompose( _("A partition cannot have a length of %1 sectors"),
partition .get_length() ) ;
return false ;
}
if ( partition .get_length() < partition .sectors_used )
{
error = String::ucompose(
_("A partition with used sectors (%1) greater than it's length (%2) is not valid"),
partition .sectors_used,
partition .get_length() ) ;
return false ;
}
//FIXME: it would be perfect if we could check for overlapping with adjacent partitions as well,
//however, finding the adjacent partitions is not as easy as it seems and at this moment all the dialogs
//already perform these checks. A perfect 'fixme-later' ;)
//FIXME: what kind of errorchecking could we do here? maybe checking if partitionlenght > used?
}
return true ;

View File

@ -148,7 +148,10 @@ void Partition::add_paths( const std::vector<Glib::ustring> & paths, bool clear_
Sector Partition::get_length() const
{
if ( sector_start >= 0 && sector_end >= 0 )
return sector_end - sector_start + 1 ;
else
return -1 ;
}
Glib::ustring Partition::get_path() const

View File

@ -616,8 +616,11 @@ void Win_GParted::Add_Operation( OperationType operationtype,
break;
}
//FIXME: do this in two separate steps and be more verbose in case of error..
if ( operation && gparted_core .snap_to_cylinder( operation ->device, operation ->partition_new ) )
if ( operation )
{
Glib::ustring error ;
if ( operation ->type == GParted::DELETE ||
gparted_core .snap_to_cylinder( operation ->device, operation ->partition_new, error ) )
{
operation ->create_description() ;
@ -628,7 +631,6 @@ void Win_GParted::Add_Operation( OperationType operationtype,
allow_undo( true ) ;
allow_apply( true ) ;
}
Refresh_Visual();
@ -640,6 +642,20 @@ void Win_GParted::Add_Operation( OperationType operationtype,
static_cast<Gtk::TreePath>( static_cast<Gtk::TreeRow>(
*(--liststore_operations ->children() .end()) ) ) ) ;
}
else
{
Gtk::MessageDialog dialog( *this,
_("Could not add this operation to the list."),
false,
Gtk::MESSAGE_ERROR,
Gtk::BUTTONS_OK,
true );
dialog .set_secondary_text( error ) ;
dialog .run() ;
}
}
}
void Win_GParted::Refresh_Visual()
{