[gparted] Refactor linux-swap recreation (#775932)



commit 2740113dcb0254c2f9bb171d0572177e213cdb60
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Nov 19 23:48:22 2016 +0000

    Refactor linux-swap recreation (#775932)
    
    Linux-swap is recreated as part of copy, resize and move operations and
    the code was special cased to implement that by calling the linux-swap
    specific resize method.  However the displayed text always said "growing
    file system" and then proceeded to recreate linux swap.  Example
    operation:
    
        Copy /dev/sdb1 to /dev/sdb2
        ...
        + copy file system from /dev/sdb1 to /dev/sdb2
            Partition copy action skipped because linux-swap file system does not contain data
        + grow file system to fill the partition
          + create new linux-swap file system
            + mkswap -L"" -U "77d939ef-54d6-427a-a2bf-a053da7eed4c" /dev/sdb2
                Setting up swapspace version 1, size = 262140 KiB
                LABEL=, UUID=77d939ef-54d6-427a-a2bf-a053da7eed4c
    
    Fix by writing recreate_linux_swap_filesystem() method with better
    messaging and use everywhere maximise_filesystem() was previously used
    to recreate linux-swap.  Also as this is a create step, erase the
    partition first to prevent the possibility of any other file system
    signatures being found afterwards.  Now the operation steps are more
    reflective of what is actually being performed.
    
        Copy /dev/sdb1 to /dev/sdb2
        ...
        + copy file system from /dev/sdb1 to /dev/sdb2
            Partition copy action skipped because linux-swap file system does not contain data
        + clear old file system signatures in /dev/sdb2
        + create new linux-swap file system
          + mkswap -L"" -U "77d939ef-54d6-427a-a2bf-a053da7eed4c" /dev/sdb2
              Setting up swapspace version 1, size = 262140 KiB
              LABEL=, UUID=77d939ef-54d6-427a-a2bf-a053da7eed4c
    
    Bug 775932 - Refactor mostly applying of operations

 include/GParted_Core.h |    2 ++
 src/GParted_Core.cc    |   33 ++++++++++++++++++++++++++++++---
 src/linux_swap.cc      |    9 +--------
 3 files changed, 33 insertions(+), 11 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index d46fc2d..73415d7 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -143,6 +143,8 @@ private:
                                const Partition & partition_new,
                                OperationDetail & operationdetail );
        bool maximize_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
+       bool recreate_linux_swap_filesystem( const Partition & partition,
+                                            OperationDetail & operationdetail );
        bool resize_filesystem_implement( const Partition & partition_old,
                                          const Partition & partition_new,
                                          OperationDetail & operationdetail );
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 8d33542..ab9af91 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -2354,7 +2354,7 @@ bool GParted_Core::move( const Partition & partition_old,
 
        if ( partition_new.filesystem == FS_LINUX_SWAP )
                // linux-swap is recreated, not moved
-               return maximize_filesystem( partition_new, operationdetail );
+               return recreate_linux_swap_filesystem( partition_new, operationdetail );
 
        return true;
 }
@@ -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 )
-                         && maximize_filesystem( partition_new, operationdetail );
+                         && recreate_linux_swap_filesystem( partition_new, operationdetail );
 
                return success;
        }
@@ -2809,6 +2809,33 @@ bool GParted_Core::maximize_filesystem( const Partition & partition, OperationDe
        return success;
 }
 
+bool GParted_Core::recreate_linux_swap_filesystem( const Partition & partition, OperationDetail & 
operationdetail )
+{
+       if ( partition.filesystem != FS_LINUX_SWAP )
+       {
+               operationdetail.add_child( OperationDetail(
+                       /* TO TRANSLATORS: looks like   not a linux-swap file system for a recreate 
linux-swap only step */
+                       GPARTED_BUG + ": " + String::ucompose( _("not a %1 file system for a recreate %1 only 
step"),
+                                                              Utils::get_filesystem_string( FS_LINUX_SWAP ),
+                                                              Utils::get_filesystem_string( FS_LINUX_SWAP ) 
),
+                       STATUS_ERROR, FONT_ITALIC ) );
+               return false;
+       }
+
+       if ( ! erase_filesystem_signatures( partition, operationdetail ) )
+               return false;
+
+       operationdetail.add_child( OperationDetail(
+               /* TO TRANSLATORS: looks like   recreate linux-swap file system */
+               String::ucompose( _("recreate %1 file system"),
+                                 Utils::get_filesystem_string( FS_LINUX_SWAP ) ) ) );
+
+       // Linux-swap is recreated by using the linux_swap::resize() method
+       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 )
@@ -2893,7 +2920,7 @@ bool GParted_Core::copy( const Partition & partition_src,
        if ( partition_dst.filesystem == FS_LINUX_SWAP )
        {
                // linux-swap is recreated, not copied
-               return maximize_filesystem( partition_dst, operationdetail );
+               return recreate_linux_swap_filesystem( partition_dst, operationdetail );
        }
        else if ( partition_dst.get_byte_length() > partition_src.get_byte_length() )
        {
diff --git a/src/linux_swap.cc b/src/linux_swap.cc
index 8d711fa..17f0b59 100644
--- a/src/linux_swap.cc
+++ b/src/linux_swap.cc
@@ -168,19 +168,12 @@ bool linux_swap::create( const Partition & new_partition, OperationDetail & oper
 
 bool linux_swap::resize( const Partition & partition_new, OperationDetail & operationdetail, bool 
fill_partition )
 {
-       /*TO TRANSLATORS: looks like create new linux-swap file system */ 
-       operationdetail .add_child( OperationDetail( 
-               String::ucompose( _("create new %1 file system"), Utils::get_filesystem_string( FS_LINUX_SWAP 
) ) ) ) ;
-
        //Maintain label and uuid when recreating swap
        Glib::ustring command = "mkswap -L \"" + partition_new.get_filesystem_label() + "\" ";
        if ( ! partition_new .uuid .empty() )
                command +=  " -U \"" + partition_new .uuid + "\" " ;
        command += partition_new .get_path() ;
-       bool exit_status = ! execute_command( command , operationdetail.get_last_child(), EXEC_CHECK_STATUS );
-
-       operationdetail .get_last_child() .set_status( exit_status ? STATUS_SUCCES : STATUS_ERROR ) ;
-       return exit_status ;
+       return ! execute_command( command, operationdetail, EXEC_CHECK_STATUS );
 }
 
 bool linux_swap::move( const Partition & partition_new


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]