[gparted] Minor tidyup in load_proc_partitions_info_cache()



commit e0a208576d00bcdf175fc401653a53483b41a87a
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue Mar 22 16:26:38 2016 +0000

    Minor tidyup in load_proc_partitions_info_cache()
    
    Minor issues:
    1) In the while loop reading from /proc/partitions into variable line,
       just after the sscanf() call the variable was re-purposed to hold the
       device name making the code unnecessarily hard to follow.
    2) Variable c_str was a fixed sized buffer holding the device name read
       from /proc/partitions.
    3) Variable c_str name provides no meaning as to what data it holds.
    4) Return value from all the Utils::regexp_label() calls is converted
       from Glib::ustring to std::string to be stored in device variable.
    
    Resolve by using Utils::regexp_label() to extract the device name from
    each line in /proc/partitions and store in the variable device, already
    used for this purpose and now changed to type Glib::ustring.

 src/Proc_Partitions_Info.cc |   21 +++++++++------------
 1 files changed, 9 insertions(+), 12 deletions(-)
---
diff --git a/src/Proc_Partitions_Info.cc b/src/Proc_Partitions_Info.cc
index 08d2e92..5e6ed74 100644
--- a/src/Proc_Partitions_Info.cc
+++ b/src/Proc_Partitions_Info.cc
@@ -84,8 +84,7 @@ void Proc_Partitions_Info::load_proc_partitions_info_cache()
        if ( proc_partitions )
        {
                std::string line ;
-               std::string device ;
-               char c_str[4096+1] ;
+               Glib::ustring device;
 
                while ( getline( proc_partitions, line ) )
                {
@@ -128,25 +127,23 @@ void Proc_Partitions_Info::load_proc_partitions_info_cache()
                        }
 
                        //Build cache of potential alternate paths
-                       if ( sscanf( line .c_str(), "%*d %*d %*d %4096s", c_str ) == 1 )
+                       device = Utils::regexp_label( line, "^[ ]*[0-9]+[ ]+[0-9]+[ ]+[0-9]+[ 
]+([[:graph:]]+)$" );
+                       if ( device != "" )
                        {
-                               line = "/dev/" ; 
-                               line += c_str ;
-
+                               device = "/dev/" + device;
                                char * rpath = NULL;
-                               if (    file_test( line, Glib::FILE_TEST_EXISTS )
-                                    && ( ( rpath = realpath( line.c_str(), NULL ) ) != NULL )
-                                   //&& line != c_str
+                               if (    file_test( device, Glib::FILE_TEST_EXISTS )
+                                    && ( ( rpath = realpath( device.c_str(), NULL ) ) != NULL )
+                                  //&& device != rpath
                                   )
                                {
                                        //Because we can make no assumption about which path libparted will
                                        //detect, we add all combinations.
-                                       alternate_paths_cache[rpath] = line;
-                                       alternate_paths_cache[line] = rpath;
+                                       alternate_paths_cache[rpath] = device;
+                                       alternate_paths_cache[device] = rpath;
                                        free( rpath );
                                }
                        }
-
                }
                proc_partitions .close() ;
        }


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