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:
parent
7f265770eb
commit
dc883ee652
|
@ -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
|
||||
|
|
|
@ -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 ) ;
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
@ -255,12 +255,27 @@ bool GParted_Core::snap_to_cylinder( const Device & device, Partition & partitio
|
|||
partition .sector_start = 0 ;
|
||||
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 ;
|
||||
|
|
|
@ -148,7 +148,10 @@ void Partition::add_paths( const std::vector<Glib::ustring> & paths, bool clear_
|
|||
|
||||
Sector Partition::get_length() const
|
||||
{
|
||||
return sector_end - sector_start + 1 ;
|
||||
if ( sector_start >= 0 && sector_end >= 0 )
|
||||
return sector_end - sector_start + 1 ;
|
||||
else
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
Glib::ustring Partition::get_path() const
|
||||
|
|
|
@ -616,29 +616,45 @@ 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 ) )
|
||||
{
|
||||
operation ->create_description() ;
|
||||
if ( operation )
|
||||
{
|
||||
Glib::ustring error ;
|
||||
if ( operation ->type == GParted::DELETE ||
|
||||
gparted_core .snap_to_cylinder( operation ->device, operation ->partition_new, error ) )
|
||||
{
|
||||
operation ->create_description() ;
|
||||
|
||||
if ( index >= 0 && index < static_cast<int>( operations .size() ) )
|
||||
operations .insert( operations .begin() + index, operation ) ;
|
||||
if ( index >= 0 && index < static_cast<int>( operations .size() ) )
|
||||
operations .insert( operations .begin() + index, operation ) ;
|
||||
else
|
||||
operations .push_back( operation );
|
||||
|
||||
allow_undo( true ) ;
|
||||
allow_apply( true ) ;
|
||||
|
||||
Refresh_Visual();
|
||||
|
||||
if ( operations .size() == 1 ) //first operation, open operationslist
|
||||
open_operationslist() ;
|
||||
|
||||
//make scrollwindow focus on the last operation in the list
|
||||
treeview_operations .set_cursor(
|
||||
static_cast<Gtk::TreePath>( static_cast<Gtk::TreeRow>(
|
||||
*(--liststore_operations ->children() .end()) ) ) ) ;
|
||||
}
|
||||
else
|
||||
operations .push_back( operation );
|
||||
{
|
||||
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 ) ;
|
||||
|
||||
allow_undo( true ) ;
|
||||
allow_apply( true ) ;
|
||||
dialog .run() ;
|
||||
}
|
||||
}
|
||||
|
||||
Refresh_Visual();
|
||||
|
||||
if ( operations .size() == 1 ) //first operation, open operationslist
|
||||
open_operationslist() ;
|
||||
|
||||
//make scrollwindow focus on the last operation in the list
|
||||
treeview_operations .set_cursor(
|
||||
static_cast<Gtk::TreePath>( static_cast<Gtk::TreeRow>(
|
||||
*(--liststore_operations ->children() .end()) ) ) ) ;
|
||||
}
|
||||
|
||||
void Win_GParted::Refresh_Visual()
|
||||
|
|
Loading…
Reference in New Issue