[gparted] Refactor resizing file system apply methods (#775932)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Refactor resizing file system apply methods (#775932)
- Date: Wed, 14 Dec 2016 21:13:07 +0000 (UTC)
commit a0158abbeb4b1116c26cfee65bd97c5063e54936
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Wed Oct 26 21:24:28 2016 +0100
Refactor resizing file system apply methods (#775932)
resize_filesystem() was meeting two different needs:
1) when called with fill_partition = false it generated operation
details;
2) when called from maximize_filesystem() with fill_partition = true it
skipped generating any operation details;
then ran the switch statement to select the resize implementation. So
extract the common switch statement into new method
resize_filesystem_implement().
Then observe that the only time resize_filesystem() was called to grow
the file system was when re-creating linux-swap. Therefore change that
call to use maximize_filesystem() and rename to shrink_filesystem() and
modify the operation detail messages to match.
Bug 775932 - Refactor mostly applying of operations
include/GParted_Core.h | 12 +++--
src/GParted_Core.cc | 135 +++++++++++++++++++++++++++---------------------
2 files changed, 83 insertions(+), 64 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index 4767848..d46fc2d 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -139,12 +139,14 @@ private:
bool resize_move_partition( const Partition & partition_old,
const Partition & partition_new,
OperationDetail & operationdetail ) ;
- bool resize_filesystem( const Partition & partition_old,
- const Partition & partition_new,
- OperationDetail & operationdetail,
- bool fill_partition = false ) ;
+ bool shrink_filesystem( const Partition & partition_old,
+ const Partition & partition_new,
+ OperationDetail & operationdetail );
bool maximize_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
-
+ bool resize_filesystem_implement( const Partition & partition_old,
+ const Partition & partition_new,
+ OperationDetail & operationdetail );
+
bool copy( const Partition & partition_src,
Partition & partition_dst,
OperationDetail & operationdetail );
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 34dc027..f4eb692 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -2521,7 +2521,7 @@ bool GParted_Core::resize( const Partition & partition_old,
{
// linux-swap is recreated, not resize
success = resize_move_partition( partition_old, partition_new, operationdetail )
- && resize_filesystem( partition_old, partition_new, operationdetail );
+ && maximize_filesystem( partition_new, operationdetail );
return success;
}
@@ -2530,7 +2530,7 @@ bool GParted_Core::resize( const Partition & partition_old,
if ( delta < 0LL ) // shrink
{
success = check_repair_filesystem( partition_new, operationdetail )
- && resize_filesystem( partition_old, partition_new, operationdetail )
+ && shrink_filesystem( partition_old, partition_new, operationdetail )
&& resize_move_partition( partition_old, partition_new, operationdetail );
}
else if ( delta > 0LL ) // grow
@@ -2747,71 +2747,38 @@ bool GParted_Core::resize_move_partition( const Partition & partition_old,
return return_value ;
}
-bool GParted_Core::resize_filesystem( const Partition & partition_old,
- const Partition & partition_new,
- OperationDetail & operationdetail,
- bool fill_partition )
+bool GParted_Core::shrink_filesystem( const Partition & partition_old,
+ const Partition & partition_new,
+ OperationDetail & operationdetail )
{
- //by default 'grow' to accomodate expand_filesystem()
- GParted::FS::Support action = get_fs( partition_old .filesystem ) .grow ;
-
- if ( ! fill_partition )
- {
- if ( partition_new .get_sector_length() < partition_old .get_sector_length() )
- {
- operationdetail .add_child( OperationDetail( _("shrink file system") ) ) ;
- action = get_fs( partition_old .filesystem ) .shrink ;
- }
- else if ( partition_new .get_sector_length() > partition_old .get_sector_length() )
- operationdetail .add_child( OperationDetail( _("grow file system") ) ) ;
- else
- {
- operationdetail .add_child( OperationDetail( _("resize file system") ) ) ;
- operationdetail .get_last_child() .add_child(
- OperationDetail(
- _("new and old file system have the same size. Hence skipping this
operation"),
- STATUS_NONE,
- FONT_ITALIC ) ) ;
-
- operationdetail .get_last_child() .set_status( STATUS_SUCCES ) ;
- return true ;
- }
- }
-
- bool succes = false ;
- FileSystem* p_filesystem = NULL ;
- switch ( action )
+ if ( partition_new.get_sector_length() >= partition_old.get_sector_length() )
{
- case GParted::FS::NONE:
- break ;
- case GParted::FS::GPARTED:
- break ;
-#ifdef HAVE_LIBPARTED_FS_RESIZE
- case GParted::FS::LIBPARTED:
- succes = resize_move_filesystem_using_libparted( partition_old,
- partition_new,
- operationdetail .get_last_child() ) ;
- break ;
-#endif
- case GParted::FS::EXTERNAL:
- succes = ( p_filesystem = get_filesystem_object( partition_new .filesystem ) ) &&
- p_filesystem ->resize( partition_new,
- operationdetail .get_last_child(),
- fill_partition ) ;
- break ;
-
- default:
- break ;
+ operationdetail.add_child( OperationDetail(
+ /* TO TRANSLATORS:
+ * means that GParted has encountered a programming bug and tried
+ * to grow the partition size or keep it the same when performing
+ * a shrink partition only step.
+ */
+ GPARTED_BUG + ": " + _("the new partition size is larger or the same for a shrink
only step"),
+ STATUS_ERROR, FONT_ITALIC ) );
+ return false;
}
- operationdetail .get_last_child() .set_status( succes ? STATUS_SUCCES : STATUS_ERROR ) ;
- return succes ;
+ bool success = resize_filesystem_implement( partition_old, partition_new, operationdetail );
+ operationdetail.get_last_child().set_status( success ? STATUS_SUCCES : STATUS_ERROR );
+ return success;
}
-
+
bool GParted_Core::maximize_filesystem( const Partition & partition, OperationDetail & operationdetail )
{
operationdetail .add_child( OperationDetail( _("grow file system to fill the partition") ) ) ;
+ // Checking if growing is available or allowed is only relevant for the check
+ // repair operation to inform the user why the grow step is being skipped. For a
+ // resize/move operation these growing checks are merely retesting those performed
+ // to allow the operation to be queued in the first place. See
+ // Win_GParted::set_valid_operations() and
+ // Dialog_Partition_Resize_Move::Resize_Move_Normal().
if ( get_fs( partition .filesystem ) .grow == GParted::FS::NONE )
{
operationdetail .get_last_child() .add_child(
@@ -2837,7 +2804,57 @@ bool GParted_Core::maximize_filesystem( const Partition & partition, OperationDe
return true ;
}
- return resize_filesystem( partition, partition, operationdetail, true ) ;
+ bool success = resize_filesystem_implement( partition, partition, operationdetail );
+ operationdetail.get_last_child().set_status( success ? STATUS_SUCCES : STATUS_ERROR );
+ return success;
+}
+
+bool GParted_Core::resize_filesystem_implement( const Partition & partition_old,
+ const Partition & partition_new,
+ OperationDetail & operationdetail )
+{
+
+ bool fill_partition = false;
+ const FS & fs_cap = get_fs( partition_new.filesystem );
+ FS::Support action = FS::NONE;
+ if ( partition_new.get_sector_length() >= partition_old.get_sector_length() )
+ {
+ // grow (always maximises the file system to fill the partition)
+ fill_partition = true;
+ action = fs_cap.grow;
+ }
+ else
+ {
+ // shrink
+ fill_partition = false;
+ action = fs_cap.shrink;
+ }
+ bool success = false;
+ FileSystem* p_filesystem = NULL;
+ switch ( action )
+ {
+ case FS::NONE:
+ break;
+ case FS::GPARTED:
+ break;
+#ifdef HAVE_LIBPARTED_FS_RESIZE
+ case FS::LIBPARTED:
+ success = resize_move_filesystem_using_libparted( partition_old,
+ partition_new,
+ operationdetail.get_last_child() );
+ break;
+#endif
+ case FS::EXTERNAL:
+ success = ( p_filesystem = get_filesystem_object( partition_new.filesystem ) ) &&
+ p_filesystem->resize( partition_new,
+ operationdetail.get_last_child(),
+ fill_partition );
+ break;
+ default:
+ break;
+ }
+
+ return success;
}
bool GParted_Core::copy( const Partition & partition_src,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]