diff --git a/ChangeLog b/ChangeLog index 169a5536..b0bbbb46 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-03-15 Bart Hakvoort + + * include/Partition.h, + src/Dialog_Partition_Info.cc, + src/GParted_Core.cc, + src/Partition.cc, + src/TreeView_Detail.cc, + src/Win_GParted.cc: Made Partition::mountpoints private + 2006-03-14 Bart Hakvoort * changed the way devices and partitions store their devicepaths. diff --git a/include/Partition.h b/include/Partition.h index 454b286c..5fa10449 100644 --- a/include/Partition.h +++ b/include/Partition.h @@ -78,6 +78,9 @@ public: Sector get_length() const ; Glib::ustring get_path() const ; std::vector get_paths() const ; + void add_mountpoints( const std::vector & mountpoints, bool clear_mountpoints = false ) ; + Glib::ustring get_mountpoint() const ; + std::vector get_mountpoints() const ; bool operator==( const Partition & partition ) const ; @@ -96,8 +99,6 @@ public: bool busy; Glib::ustring error; std::vector flags ; - std::vector mountpoints ;//FIXME: it's better to make this one private as well to prevent segfaults - //when callong mountpoints .front() on an empty list. std::vector logicals ; @@ -109,6 +110,7 @@ private: static bool compare_paths( const Glib::ustring & A, const Glib::ustring & B ) ; std::vector paths ; + std::vector mountpoints ; }; }//GParted diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc index f6b3bcfc..d13cfc25 100644 --- a/src/Dialog_Partition_Info.cc +++ b/src/Dialog_Partition_Info.cc @@ -195,9 +195,9 @@ void Dialog_Partition_Info::Display_Info( ) str_temp = _("Busy (At least one logical partition is mounted)" ) ; else if ( partition .filesystem == FS_LINUX_SWAP ) str_temp = _("Active") ; - else if ( partition .mountpoints .size() ) + else if ( partition .get_mountpoints() .size() ) str_temp = String::ucompose( _("Mounted on %1"), - Glib::build_path( ", ", partition .mountpoints ) ) ; + Glib::build_path( ", ", partition .get_mountpoints() ) ) ; } else if ( partition.type == GParted::TYPE_EXTENDED ) str_temp = _("Not busy (There are no mounted logical partitions)" ) ; diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 533768a7..33a3246d 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -405,19 +405,19 @@ void GParted_Core::set_mountpoints( std::vector & partitions ) iter_mp = mount_info .find( partitions[ t ] .get_paths()[ i ] ) ; if ( iter_mp != mount_info .end() ) { - partitions[ t ] .mountpoints = iter_mp ->second ; + partitions[ t ] .add_mountpoints( iter_mp ->second ) ; break ; } } - if ( partitions[ t ] .mountpoints .empty() ) + if ( partitions[ t ] .get_mountpoints() .empty() ) partitions[ t ] .error = _("Unable to find mountpoint") ; } else { iter_mp = fstab_info .find( partitions[ t ] .get_path() ); if ( iter_mp != fstab_info .end() ) - partitions[ t ] .mountpoints = iter_mp ->second ; + partitions[ t ] .add_mountpoints( iter_mp ->second ) ; } } else if ( partitions[ t ] .type == GParted::TYPE_EXTENDED ) @@ -456,13 +456,13 @@ void GParted_Core::set_used_sectors( std::vector & partitions ) { if ( partitions[ t ] .busy ) { - if ( partitions[ t ] .mountpoints .size() > 0 ) + if ( partitions[ t ] .get_mountpoints() .size() > 0 ) { - if ( statvfs( partitions[ t ] .mountpoints .front() .c_str(), &sfs ) == 0 ) + if ( statvfs( partitions[ t ] .get_mountpoint() .c_str(), &sfs ) == 0 ) partitions[ t ] .Set_Unused( sfs .f_bfree * (sfs .f_bsize / 512) ) ; else partitions[ t ] .error = - "statvfs (" + partitions[ t ] .mountpoints .front() + "): " + Glib::strerror( errno ); + "statvfs (" + partitions[ t ] .get_mountpoint() + "): " + Glib::strerror( errno ); } } else diff --git a/src/Partition.cc b/src/Partition.cc index f44aced5..a1567031 100644 --- a/src/Partition.cc +++ b/src/Partition.cc @@ -172,6 +172,27 @@ void Partition::sort_paths_and_remove_duplicates() std::sort( paths .begin(), paths .end(), compare_paths ) ; } +void Partition::add_mountpoints( const std::vector & mountpoints, bool clear_mountpoints ) +{ + if ( clear_mountpoints ) + this ->mountpoints .clear() ; + + this ->mountpoints .insert( this ->mountpoints .end(), mountpoints .begin(), mountpoints .end() ) ; +} + +Glib::ustring Partition::get_mountpoint() const +{ + if ( mountpoints .size() > 0 ) + return mountpoints .front() ; + + return "" ; +} + +std::vector Partition::get_mountpoints() const +{ + return mountpoints ; +} + bool Partition::compare_paths( const Glib::ustring & A, const Glib::ustring & B ) { return A .length() < B .length() ; diff --git a/src/TreeView_Detail.cc b/src/TreeView_Detail.cc index f5f8af34..0116ed1f 100644 --- a/src/TreeView_Detail.cc +++ b/src/TreeView_Detail.cc @@ -99,12 +99,12 @@ void TreeView_Detail::load_partitions( const std::vector & partitions childrow = *( treestore_detail ->append( row.children() ) ); create_row( childrow, partitions[ i ] .logicals[ t ] ); - if ( partitions[ i ] .logicals[ t ] .mountpoints .size() ) + if ( partitions[ i ] .logicals[ t ] .get_mountpoints() .size() ) mount_info = true ; } } - if ( partitions[ i ] .mountpoints .size() ) + if ( partitions[ i ] .get_mountpoints() .size() ) mount_info = true ; } @@ -172,7 +172,7 @@ void TreeView_Detail::create_row( const Gtk::TreeRow & treerow, const Partition //mountpoint treerow[ treeview_detail_columns .mount_text_color ] = partition .busy ? "black" : "darkgrey" ; - treerow[ treeview_detail_columns .mountpoint ] = Glib::build_path( ", ", partition .mountpoints ) ; + treerow[ treeview_detail_columns .mountpoint ] = Glib::build_path( ", ", partition .get_mountpoints() ) ; //size treerow[ treeview_detail_columns .size ] = Utils::format_size( partition .get_length() ) ; diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 6205d01e..0aeaa3de 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -756,7 +756,7 @@ void Win_GParted::set_valid_operations() if ( selected_partition .status == GParted::STAT_REAL && fs .copy ) allow_copy( true ) ; - if ( selected_partition .mountpoints .size() ) + if ( selected_partition .get_mountpoints() .size() ) { allow_toggle_swap_mount_state( true ) ; @@ -1372,10 +1372,12 @@ void Win_GParted::thread_unmount_partition( bool * succes, Glib::ustring * error Glib::ustring dummy ; *succes = true ; - for ( unsigned int t = 0 ; t < selected_partition .mountpoints .size() ; t++ ) - if ( std::count( mountpoints .begin(), mountpoints .end(), selected_partition .mountpoints[ t ] ) <= 1 ) + for ( unsigned int t = 0 ; t < selected_partition .get_mountpoints() .size() ; t++ ) + if ( std::count( mountpoints .begin(), + mountpoints .end(), + selected_partition .get_mountpoints()[ t ] ) <= 1 ) { - if ( Utils::execute_command( "umount -v " + selected_partition .mountpoints[ t ], + if ( Utils::execute_command( "umount -v " + selected_partition .get_mountpoints()[ t ], dummy, *error ) ) { @@ -1384,7 +1386,7 @@ void Win_GParted::thread_unmount_partition( bool * succes, Glib::ustring * error } } else - failed_mountpoints .push_back( selected_partition .mountpoints[ t ] ) ; + failed_mountpoints .push_back( selected_partition .get_mountpoints()[ t ] ) ; if ( *succes && failed_mountpoints .size() ) @@ -1406,10 +1408,11 @@ void Win_GParted::thread_mount_partition( bool * succes, Glib::ustring * error ) std::vector errors ; *succes = true ; - for ( unsigned int t = 0 ; t < selected_partition .mountpoints .size() ; t++ ) - if ( Utils::execute_command( "mount -v " + selected_partition .get_path() + " " + selected_partition .mountpoints[ t ], - dummy, - *error ) ) + for ( unsigned int t = 0 ; t < selected_partition .get_mountpoints() .size() ; t++ ) + if ( Utils::execute_command( + "mount -v " + selected_partition .get_path() + " " + selected_partition .get_mountpoints()[ t ], + dummy, + *error ) ) { *succes = false ; errors .push_back( *error ) ;