From f0eb17b8db568dccdf1dbe6357910f830650e1aa Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Tue, 30 Nov 2004 21:05:48 +0000 Subject: [PATCH] Execute_Command() now returns exit status of executed command returnvalue * include/FileSystem.h, src/FileSystem.cc: Execute_Command() now returns exit status of executed command * the filesystemclasses: returnvalue (bool) is now set according to the return status of the command --- ChangeLog | 6 ++++++ include/FileSystem.h | 2 +- src/FileSystem.cc | 9 +++------ src/ext2.cc | 8 ++++---- src/ext3.cc | 8 ++++---- src/fat16.cc | 2 +- src/fat32.cc | 4 ++-- src/linux_swap.cc | 2 +- src/ntfs.cc | 12 +++++++----- src/reiserfs.cc | 18 ++++++++++++------ 10 files changed, 41 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 29d23cb9..cb176115 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-11-30 Bart Hakvoort + + * include/FileSystem.h, + src/FileSystem.cc: Execute_Command() now returns exit status of executed command + * the filesystemclasses: returnvalue (bool) is now set according to the return status of the command + 2004-11-29 Bart Hakvoort * src/GParted_Core.cc: It seemed some kernels remove and re-add blockdevicepaths after the commit_to_os. This caused trouble at some points diff --git a/include/FileSystem.h b/include/FileSystem.h index e0e042f3..e31da2f8 100644 --- a/include/FileSystem.h +++ b/include/FileSystem.h @@ -95,7 +95,7 @@ public: long cylinder_size ; //see GParted_Core::Resize() protected: - bool Execute_Command( Glib::ustring command ) ; + int Execute_Command( Glib::ustring command ) ; PedDevice *device ; diff --git a/src/FileSystem.cc b/src/FileSystem.cc index 534c808d..95701706 100644 --- a/src/FileSystem.cc +++ b/src/FileSystem.cc @@ -27,7 +27,7 @@ FileSystem::FileSystem( ) cylinder_size = 0 ; } -bool FileSystem::Execute_Command( Glib::ustring command ) +int FileSystem::Execute_Command( Glib::ustring command ) { Glib::Dispatcher dispatcher; sigc::connection conn = dispatcher .connect( sigc::mem_fun(*this, &FileSystem::Update_Textview) ); @@ -48,13 +48,10 @@ bool FileSystem::Execute_Command( Glib::ustring command ) //dispatcher ( ) ;disabled for the moment. Hier moet ik nog eens fris naar kijken. (anjuta had zo'n ingebouwde terminal, hoe deed die dat?? !!! } - pclose( f ) ; - output = "" ; - dispatcher ( ) ; + dispatcher( ) ; - - return true ; + return pclose( f ) ; } void FileSystem::Update_Textview( ) diff --git a/src/ext2.cc b/src/ext2.cc index 8da3c8a5..0d0898db 100644 --- a/src/ext2.cc +++ b/src/ext2.cc @@ -76,7 +76,7 @@ void ext2::Set_Used_Sectors( Partition & partition ) bool ext2::Create( const Glib::ustring device_path, const Partition & new_partition ) { - return Execute_Command( "mkfs.ext2 " + new_partition .partition ) ; + return ! Execute_Command( "mkfs.ext2 " + new_partition .partition ) ; } bool ext2::Resize( const Partition & partition_new, bool fill_partition ) @@ -86,17 +86,17 @@ bool ext2::Resize( const Partition & partition_new, bool fill_partition ) if ( ! fill_partition ) str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ; - return Execute_Command( str_temp ) ; + return ! Execute_Command( str_temp ) ; } bool ext2::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) { - return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; + return ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } bool ext2::Check_Repair( const Partition & partition ) { - return Execute_Command( "e2fsck -fy " + partition .partition ) ; + return Execute_Command( "e2fsck -fy " + partition .partition ) <= 1 ; } int ext2::get_estimated_time( long MB_to_Consider ) diff --git a/src/ext3.cc b/src/ext3.cc index d3f55ceb..f08c7220 100644 --- a/src/ext3.cc +++ b/src/ext3.cc @@ -76,7 +76,7 @@ void ext3::Set_Used_Sectors( Partition & partition ) bool ext3::Create( const Glib::ustring device_path, const Partition & new_partition ) { - return Execute_Command( "mkfs.ext3 " + new_partition .partition ) ; + return ! Execute_Command( "mkfs.ext3 " + new_partition .partition ) ; } bool ext3::Resize( const Partition & partition_new, bool fill_partition ) @@ -86,17 +86,17 @@ bool ext3::Resize( const Partition & partition_new, bool fill_partition ) if ( ! fill_partition ) str_temp += " " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ; - return Execute_Command( str_temp ) ; + return ! Execute_Command( str_temp ) ; } bool ext3::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) { - return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; + return ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } bool ext3::Check_Repair( const Partition & partition ) { - return Execute_Command( "e2fsck -fy " + partition .partition ) ; + return Execute_Command( "e2fsck -fy " + partition .partition ) <= 1 ; } int ext3::get_estimated_time( long MB_to_Consider ) diff --git a/src/fat16.cc b/src/fat16.cc index 047301e5..90a67af0 100644 --- a/src/fat16.cc +++ b/src/fat16.cc @@ -107,7 +107,7 @@ bool fat16::Resize( const Partition & partition_new, bool fill_partition ) bool fat16::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) { - return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; + return ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } bool fat16::Check_Repair( const Partition & partition ) diff --git a/src/fat32.cc b/src/fat32.cc index 68b95c05..67a7a2ac 100644 --- a/src/fat32.cc +++ b/src/fat32.cc @@ -73,7 +73,7 @@ void fat32::Set_Used_Sectors( Partition & partition ) bool fat32::Create( const Glib::ustring device_path, const Partition & new_partition ) { - return Execute_Command( "mkdosfs -F32 " + new_partition .partition ) ; + return ! Execute_Command( "mkdosfs -F32 " + new_partition .partition ) ; } bool fat32::Resize( const Partition & partition_new, bool fill_partition ) @@ -84,7 +84,7 @@ bool fat32::Resize( const Partition & partition_new, bool fill_partition ) bool fat32::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) { - return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; + return ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } bool fat32::Check_Repair( const Partition & partition ) diff --git a/src/linux_swap.cc b/src/linux_swap.cc index 1dca860b..de82b6db 100644 --- a/src/linux_swap.cc +++ b/src/linux_swap.cc @@ -82,7 +82,7 @@ bool linux_swap::Resize( const Partition & partition_new, bool fill_partition ) bool linux_swap::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) { - return Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; + return ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; } bool linux_swap::Check_Repair( const Partition & partition ) diff --git a/src/ntfs.cc b/src/ntfs.cc index 7f377515..1effb377 100644 --- a/src/ntfs.cc +++ b/src/ntfs.cc @@ -72,7 +72,7 @@ void ntfs::Set_Used_Sectors( Partition & partition ) bool ntfs::Create( const Glib::ustring device_path, const Partition & new_partition ) { - return Execute_Command( "mkntfs -Q " + new_partition .partition ) ; + return ! Execute_Command( "mkntfs -Q " + new_partition .partition ) ; } bool ntfs::Resize( const Partition & partition_new, bool fill_partition ) @@ -82,22 +82,24 @@ bool ntfs::Resize( const Partition & partition_new, bool fill_partition ) if ( ! fill_partition ) str_temp += " -s " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ; - return Execute_Command( str_temp ) ; + return ! Execute_Command( str_temp ) ; } bool ntfs::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) { - Execute_Command( "ntfsclone -f --overwrite " + dest_part_path + " " + src_part_path ) ; + bool ret_val = ! Execute_Command( "ntfsclone -f --overwrite " + dest_part_path + " " + src_part_path ) ; //resize to full to set correct used/unused - return Execute_Command( "echo y | ntfsresize -f " + dest_part_path ) ; + Execute_Command( "echo y | ntfsresize -f " + dest_part_path ) ; + + return ret_val ; } bool ntfs::Check_Repair( const Partition & partition ) { //according to Szaka it's best to use ntfsresize to check the partition for errors //since --info is read-only i'll leave it out. just calling ntfsresize --force has also a tendency of fixing stuff :) - return Execute_Command( "echo y | ntfsresize -f " + partition .partition ) ; + return ! Execute_Command( "echo y | ntfsresize -f " + partition .partition ) ; } int ntfs::get_estimated_time( long MB_to_Consider ) diff --git a/src/reiserfs.cc b/src/reiserfs.cc index 2e38bd39..6c49716c 100644 --- a/src/reiserfs.cc +++ b/src/reiserfs.cc @@ -77,7 +77,7 @@ void reiserfs::Set_Used_Sectors( Partition & partition ) bool reiserfs::Create( const Glib::ustring device_path, const Partition & new_partition ) { - return Execute_Command( "mkreiserfs -q " + new_partition .partition ) ; + return ! Execute_Command( "mkreiserfs -q " + new_partition .partition ) ; } bool reiserfs::Resize( const Partition & partition_new, bool fill_partition ) @@ -87,21 +87,27 @@ bool reiserfs::Resize( const Partition & partition_new, bool fill_partition ) if ( ! fill_partition ) str_temp += " -s " + num_to_str( partition_new .Get_Length_MB( ) - cylinder_size ) + "M" ; - return Execute_Command( str_temp ) ; + return ! Execute_Command( str_temp ) ; } bool reiserfs::Copy( const Glib::ustring & src_part_path, const Glib::ustring & dest_part_path ) -{ +{ //copy partition - Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; + bool ret_val = ! Execute_Command( "dd bs=8192 if=" + src_part_path + " of=" + dest_part_path ) ; //and set proper used/unused - return Execute_Command( "resize_reiserfs " + dest_part_path ) ; + Execute_Command( "resize_reiserfs " + dest_part_path ) ; + + return ret_val ; } bool reiserfs::Check_Repair( const Partition & partition ) { - return Execute_Command( "reiserfsck -y --fix-fixable " + partition .partition ) ; + //according to the manpage it should return 0 or 1 on succes, instead it returns 256 on succes.. + //blah, don't have time for this. Just check for both options, we'll fix this in 0.0.8 with our much improved errorhandling + int t = Execute_Command( "reiserfsck -y --fix-fixable " + partition .partition ) ; + + return ( t <=1 || t == 256 ) ; } int reiserfs::get_estimated_time( long MB_to_Consider )