[gparted/psusi/refactor: 16/19] Combine duplicate code for ext[234]



commit c4511884c1eaa7d87f826351f63158250684cc1e
Author: Phillip Susi <psusi ubuntu com>
Date:   Mon Jan 21 15:41:24 2013 -0500

    Combine duplicate code for ext[234]
    
    There were separate modules for ext3 and ext4 even though there
    were virtually no differences with ext2.  Remove the duplicate
    modules and patch ext2 to serve as a common reference for all
    three sub types.

 include/Makefile.am |    2 -
 include/ext2.h      |    2 +
 include/ext3.h      |   53 -------------
 include/ext4.h      |   52 ------------
 src/GParted_Core.cc |    8 +-
 src/Makefile.am     |    2 -
 src/ext2.cc         |   70 +++++++++--------
 src/ext3.cc         |  215 --------------------------------------------------
 src/ext4.cc         |  217 ---------------------------------------------------
 9 files changed, 43 insertions(+), 578 deletions(-)
---
diff --git a/include/Makefile.am b/include/Makefile.am
index 7a8f1df..98a227c 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -40,8 +40,6 @@ EXTRA_DIST = \
        btrfs.h                         \
        exfat.h                         \
        ext2.h                          \
-       ext3.h                          \
-       ext4.h                          \
        fat16.h                         \
        fat32.h                         \
        hfs.h                           \
diff --git a/include/ext2.h b/include/ext2.h
index 6b76d62..8d4f9dc 100644
--- a/include/ext2.h
+++ b/include/ext2.h
@@ -27,7 +27,9 @@ namespace GParted
 
 class ext2 : public FileSystem
 {
+       const enum FILESYSTEM specific_type;
 public:
+       ext2( enum FILESYSTEM type ) : specific_type( type ) {};
        FS get_filesystem_support() ;
        void set_used_sectors( Partition & partition ) ;
        void read_label( Partition & partition ) ;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 41b1873..53f880f 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -33,8 +33,6 @@
 #include "../include/btrfs.h"
 #include "../include/exfat.h"
 #include "../include/ext2.h"
-#include "../include/ext3.h"
-#include "../include/ext4.h"
 #include "../include/fat16.h"
 #include "../include/fat32.h"
 #include "../include/linux_swap.h"
@@ -100,9 +98,9 @@ void GParted_Core::find_supported_filesystems()
 
        FILESYSTEM_MAP[ FS_BTRFS ]      = new btrfs() ;
        FILESYSTEM_MAP[ FS_EXFAT ]      = new exfat() ;
-       FILESYSTEM_MAP[ FS_EXT2 ]       = new ext2() ;
-       FILESYSTEM_MAP[ FS_EXT3 ]       = new ext3() ;
-       FILESYSTEM_MAP[ FS_EXT4 ]       = new ext4() ;
+       FILESYSTEM_MAP[ FS_EXT2 ]       = new ext2( FS_EXT2 ) ;
+       FILESYSTEM_MAP[ FS_EXT3 ]       = new ext2( FS_EXT3 ) ;
+       FILESYSTEM_MAP[ FS_EXT4 ]       = new ext2( FS_EXT4 ) ;
        FILESYSTEM_MAP[ FS_FAT16 ]      = new fat16() ;
        FILESYSTEM_MAP[ FS_FAT32 ]      = new fat32() ;
        FILESYSTEM_MAP[ FS_HFS ]        = new hfs() ;
diff --git a/src/Makefile.am b/src/Makefile.am
index 16c0277..28feb63 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -50,8 +50,6 @@ gpartedbin_SOURCES = \
        btrfs.cc                        \
        exfat.cc                        \
        ext2.cc                         \
-       ext3.cc                         \
-       ext4.cc                         \
        fat16.cc                        \
        fat32.cc                        \
        hfs.cc                          \
diff --git a/src/ext2.cc b/src/ext2.cc
index 2f113b5..0251903 100644
--- a/src/ext2.cc
+++ b/src/ext2.cc
@@ -24,42 +24,48 @@ namespace GParted
 FS ext2::get_filesystem_support()
 {
        FS fs ;
-       fs .filesystem = FS_EXT2 ;
+       fs .filesystem = specific_type;
 
-       if ( ! Glib::find_program_in_path( "dumpe2fs" ) .empty() )
-               fs .read = FS::EXTERNAL ;
+       //Only enable any functionality if the relevant mkfs.extX command is
+       //  found to ensure that the version of e2fsprogs is new enough to
+       //  support ext4.  Applying to ext2/3 too is OK as relevant mkfs.ext2/3
+       //  commands exist.
+       if ( ! Glib::find_program_in_path( "mkfs." + Utils::get_filesystem_string( specific_type ) ).empty() )
+       {
+               fs .create = FS::EXTERNAL ;
 
-       if ( ! Glib::find_program_in_path( "tune2fs" ) .empty() ) {
-               fs .read_uuid = FS::EXTERNAL ;
-               fs .write_uuid = FS::EXTERNAL ;
-       }
+               if ( ! Glib::find_program_in_path( "dumpe2fs" ) .empty() )
+                       fs .read = FS::EXTERNAL ;
 
-       if ( ! Glib::find_program_in_path( "e2label" ) .empty() ) {
-               fs .read_label = FS::EXTERNAL ;
-               fs .write_label = FS::EXTERNAL ;
-       }
-       
-       if ( ! Glib::find_program_in_path( "mkfs.ext2" ) .empty() )
-               fs .create = FS::EXTERNAL ;
-       
-       if ( ! Glib::find_program_in_path( "e2fsck" ) .empty() )
-               fs .check = FS::EXTERNAL ;
+               if ( ! Glib::find_program_in_path( "tune2fs" ) .empty() ) {
+                       fs .read_uuid = FS::EXTERNAL ;
+                       fs .write_uuid = FS::EXTERNAL ;
+               }
+
+               if ( ! Glib::find_program_in_path( "e2label" ) .empty() ) {
+                       fs .read_label = FS::EXTERNAL ;
+                       fs .write_label = FS::EXTERNAL ;
+               }
+
+               if ( ! Glib::find_program_in_path( "e2fsck" ) .empty() )
+                       fs .check = FS::EXTERNAL ;
        
-       if ( ! Glib::find_program_in_path( "resize2fs" ) .empty() && fs .check )
-       {
-               fs .grow = FS::EXTERNAL ;
-               
-               if ( fs .read ) //needed to determine a min file system size..
-                       fs .shrink = FS::EXTERNAL ;
-       }
+               if ( ! Glib::find_program_in_path( "resize2fs" ) .empty() && fs .check )
+               {
+                       fs .grow = FS::EXTERNAL ;
 
-       if ( fs .check )
-       {
-               fs .copy = FS::GPARTED ;
-               fs .move = FS::GPARTED ;
-       }
+                       if ( fs .read ) //needed to determine a min file system size..
+                               fs .shrink = FS::EXTERNAL ;
+               }
 
-       fs .online_read = FS::EXTERNAL ;
+               if ( fs .check )
+               {
+                       fs .copy = FS::GPARTED ;
+                       fs .move = FS::GPARTED ;
+               }
+
+               fs .online_read = FS::EXTERNAL ;
+       }
 
        return fs ;
 }
@@ -167,8 +173,8 @@ bool ext2::write_uuid( const Partition & partition, OperationDetail & operationd
 
 bool ext2::create( const Partition & new_partition, OperationDetail & operationdetail )
 {
-       return ! execute_command( "mkfs.ext2 -L \"" +
-                                 new_partition.get_label() + "\" " + new_partition.get_path(),
+       return ! execute_command( "mkfs." + Utils::get_filesystem_string( specific_type ) +
+                                 " -L \"" + new_partition.get_label() + "\" " + new_partition.get_path(),
                                  operationdetail,
                                  false,
                                  true );


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