Prefix xfs member variables with m_ and initialise POD member

To make it clear they are xfs member variables.  Also add a default
constructor with an initialisation list so POD (Plain Old Data) member
variable m_src_used is never left uninitialised, as it was previously
only assigned in xfs::copy().  m_dest_mount_point is a Glib::ustring
object which is default constructed to a zero length string so doesn't
need adding to the xfs default constructor initialisation list.

* C++ FAQ / Should my constructors use "initialization lists" or
  "assignment"?
  https://isocpp.org/wiki/faq/ctors#init-lists
      "Initialization lists.  In fact, constructors should initialize as
      a rule all member objects in the initialization list."
This commit is contained in:
Mike Fleetwood 2024-08-04 12:59:19 +01:00
parent 181a801734
commit bac9e399b8
2 changed files with 16 additions and 13 deletions

View File

@ -32,6 +32,8 @@ namespace GParted
class xfs : public FileSystem class xfs : public FileSystem
{ {
public: public:
xfs() : m_src_used(-1LL) {};
FS get_filesystem_support() ; FS get_filesystem_support() ;
void set_used_sectors( Partition & partition ) ; void set_used_sectors( Partition & partition ) ;
void read_label( Partition & partition ) ; void read_label( Partition & partition ) ;
@ -48,10 +50,11 @@ public:
private: private:
bool copy_progress( OperationDetail * operationdetail ); bool copy_progress( OperationDetail * operationdetail );
Byte_Value src_used; // Used bytes in the source FS of an XFS copy operation Byte_Value m_src_used; // Used bytes in the source FS of an XFS copy operation
Glib::ustring dest_mount_point; // Temporary FS mount point of an XFS copy operation Glib::ustring m_dest_mount_point; // Temporary FS mount point of an XFS copy operation
}; };
} //GParted } //GParted
#endif /* GPARTED_XFS_H */ #endif /* GPARTED_XFS_H */

View File

@ -272,8 +272,8 @@ bool xfs::copy( const Partition & src_part,
if ( src_mount_point .empty() ) if ( src_mount_point .empty() )
return false ; return false ;
dest_mount_point = mk_temp_dir( "dest", operationdetail ); m_dest_mount_point = mk_temp_dir("dest", operationdetail);
if ( dest_mount_point .empty() ) if (m_dest_mount_point.empty())
{ {
rm_temp_dir( src_mount_point, operationdetail ) ; rm_temp_dir( src_mount_point, operationdetail ) ;
return false ; return false ;
@ -287,26 +287,26 @@ bool xfs::copy( const Partition & src_part,
Byte_Value fs_size; Byte_Value fs_size;
Byte_Value fs_free; Byte_Value fs_free;
if ( Utils::get_mounted_filesystem_usage( src_mount_point, fs_size, fs_free, error ) == 0 ) if ( Utils::get_mounted_filesystem_usage( src_mount_point, fs_size, fs_free, error ) == 0 )
src_used = fs_size - fs_free; m_src_used = fs_size - fs_free;
else else
src_used = -1LL; m_src_used = -1LL;
if ( success ) if ( success )
{ {
success &= ! execute_command("mount -v -t xfs -o nouuid " + Glib::shell_quote(dest_part.get_path()) + success &= ! execute_command("mount -v -t xfs -o nouuid " + Glib::shell_quote(dest_part.get_path()) +
" " + Glib::shell_quote(dest_mount_point), " " + Glib::shell_quote(m_dest_mount_point),
operationdetail, EXEC_CHECK_STATUS); operationdetail, EXEC_CHECK_STATUS);
if ( success ) if ( success )
{ {
const Glib::ustring copy_cmd = "xfsdump -J - " + Glib::shell_quote( src_mount_point ) + const Glib::ustring copy_cmd = "xfsdump -J - " + Glib::shell_quote( src_mount_point ) +
" | xfsrestore -J - " + Glib::shell_quote( dest_mount_point ); " | xfsrestore -J - " + Glib::shell_quote(m_dest_mount_point);
success &= ! execute_command( "sh -c " + Glib::shell_quote( copy_cmd ), success &= ! execute_command( "sh -c " + Glib::shell_quote( copy_cmd ),
operationdetail, operationdetail,
EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_TIMED, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE|EXEC_PROGRESS_TIMED,
static_cast<TimedSlot>( sigc::mem_fun( *this, &xfs::copy_progress ) ) ); static_cast<TimedSlot>( sigc::mem_fun( *this, &xfs::copy_progress ) ) );
success &= ! execute_command( "umount -v " + Glib::shell_quote( dest_mount_point ), success &= ! execute_command( "umount -v " + Glib::shell_quote(m_dest_mount_point),
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
@ -314,7 +314,7 @@ bool xfs::copy( const Partition & src_part,
operationdetail, EXEC_CHECK_STATUS ); operationdetail, EXEC_CHECK_STATUS );
} }
rm_temp_dir( dest_mount_point, operationdetail ) ; rm_temp_dir(m_dest_mount_point, operationdetail);
rm_temp_dir( src_mount_point, operationdetail ) ; rm_temp_dir( src_mount_point, operationdetail ) ;
@ -333,7 +333,7 @@ bool xfs::check_repair( const Partition & partition, OperationDetail & operation
// recorded source FS used bytes. // recorded source FS used bytes.
bool xfs::copy_progress( OperationDetail * operationdetail ) bool xfs::copy_progress( OperationDetail * operationdetail )
{ {
if ( src_used <= 0LL ) if (m_src_used <= 0LL)
{ {
operationdetail->stop_progressbar(); operationdetail->stop_progressbar();
// Failed to get source FS used bytes. Remove this timed callback early. // Failed to get source FS used bytes. Remove this timed callback early.
@ -342,14 +342,14 @@ bool xfs::copy_progress( OperationDetail * operationdetail )
Byte_Value fs_size; Byte_Value fs_size;
Byte_Value fs_free; Byte_Value fs_free;
Byte_Value dst_used; Byte_Value dst_used;
if ( Utils::get_mounted_filesystem_usage( dest_mount_point, fs_size, fs_free, error ) != 0 ) if (Utils::get_mounted_filesystem_usage(m_dest_mount_point, fs_size, fs_free, error) != 0)
{ {
operationdetail->stop_progressbar(); operationdetail->stop_progressbar();
// Failed to get destination FS used bytes. Remove this timed callback early. // Failed to get destination FS used bytes. Remove this timed callback early.
return false; return false;
} }
dst_used = fs_size - fs_free; dst_used = fs_size - fs_free;
operationdetail->run_progressbar( (double)dst_used, (double)src_used, PROGRESSBAR_TEXT_COPY_BYTES ); operationdetail->run_progressbar((double)dst_used, (double)m_src_used, PROGRESSBAR_TEXT_COPY_BYTES);
return true; return true;
} }