[gparted] Refactor some logic into separate get_udev_name method



commit 9816f5c18ac089aead6a550ad97cbfae56a86ee0
Author: Curtis Gedak <gedakc gmail com>
Date:   Tue Apr 28 13:42:47 2009 -0600

    Refactor some logic into separate get_udev_name method
---
 include/DMRaid.h |    1 +
 src/DMRaid.cc    |   40 ++++++++++++++++++++++++++--------------
 2 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/include/DMRaid.h b/include/DMRaid.h
index 21c3188..c3a624d 100644
--- a/include/DMRaid.h
+++ b/include/DMRaid.h
@@ -53,6 +53,7 @@ public:
 	Glib::ustring get_dmraid_name( const Glib::ustring & dev_path ) ;
 	Glib::ustring get_dmraid_prefix( const Glib::ustring & dev_path ) ;
 	int get_partition_number( const Glib::ustring & partition_name ) ;
+	Glib::ustring get_udev_name( const Glib::ustring & dev_path ) ;
 	bool create_dev_map_entries( const Partition & partition, OperationDetail & operationdetail ) ;
 	bool create_dev_map_entries( const Glib::ustring & dev_path ) ;
 	bool delete_affected_dev_map_entries( const Partition & partition, OperationDetail & operationdetail ) ;
diff --git a/src/DMRaid.cc b/src/DMRaid.cc
index ea98a78..5f5943d 100644
--- a/src/DMRaid.cc
+++ b/src/DMRaid.cc
@@ -112,22 +112,11 @@ bool DMRaid::is_dmraid_device( const Glib::ustring & dev_path )
 	//  also check with udev to see if they are in fact dmraid devices
 	if ( ! device_found && ( dev_path .find( "/dev/dm" ) != Glib::ustring::npos ) )
 	{
-		Glib::ustring output = "" ;
-		Glib::ustring error  = "" ;
-		Glib::ustring alt_udev_path = "" ;
-		if ( udevinfo_found )
-			if ( ! Utils::execute_command( "udevinfo --query=name --name=" + dev_path, output, error, true ) )
-				alt_udev_path = output ;
-		else if ( udevadm_found )
-			if ( ! Utils::execute_command( "udevadm info --query=name --name=" + DEV_MAP_PATH + dev_path, output, error, true ) )
-				alt_udev_path = output ;
-		if ( ! alt_udev_path .empty() )
-		{
+		Glib::ustring udev_name = get_udev_name( dev_path ) ;
+		if ( ! udev_name .empty() )
 			for ( unsigned int k=0; k < dmraid_devices .size(); k++ )
-				if ( alt_udev_path .find( dmraid_devices[k] ) != Glib::ustring::npos )
+				if ( udev_name .find( dmraid_devices[k] ) != Glib::ustring::npos )
 					device_found = true ;
-					
-		}
 	}
 
 	return device_found ;
@@ -221,6 +210,29 @@ int DMRaid::get_partition_number( const Glib::ustring & partition_name )
 	return std::atoi( Utils::regexp_label( partition_name, dmraid_name + "p?([0-9]+)" ) .c_str() ) ;
 }
 
+Glib::ustring DMRaid::get_udev_name( const Glib::ustring & dev_path )
+{
+	//Retrieve name of device using udev information
+	Glib::ustring output = "" ;
+	Glib::ustring error  = "" ;
+	Glib::ustring udev_name = "" ;
+
+	if ( udevinfo_found )
+		if ( ! Utils::execute_command( "udevinfo --query=name --name=" + dev_path, output, error, true ) )
+			udev_name = output ;
+	else if ( udevadm_found )
+		if ( ! Utils::execute_command( "udevadm info --query=name --name=" + DEV_MAP_PATH + dev_path, output, error, true ) )
+			udev_name = output ;
+	if ( ! udev_name .empty() )
+	{
+		//Extract portion of name after last '/'
+		udev_name = Utils::regexp_label( udev_name, "([^/]*)$" ) ;
+	}
+
+std::cout << "dev_path: " << dev_path << ", udev_name: " << udev_name << std::endl;
+	return udev_name ;
+}
+
 bool DMRaid::create_dev_map_entries( const Partition & partition, OperationDetail & operationdetail )
 {
 	//Create all missing dev mapper entries for a specified device.



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