[gparted] Enhance file parsing to handle tabs properly (#582687)



commit 5f3c806561ff55a1a89f0dbdc1d1ac5020af127f
Author: Curtis Gedak <gedakc gmail com>
Date:   Thu Jul 23 16:03:42 2009 -0600

    Enhance file parsing to handle tabs properly (#582687)
    
    Previously the read_mountpoints_from_file() method only expected
    a space between arguments in files such as /etc/fstab.  Valid
    delimiters are now space and tab.
    
    Related to GParted bug #582687

 src/GParted_Core.cc |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 259ab7e..5ffa606 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -634,28 +634,28 @@ void GParted_Core::read_mountpoints_from_file(
 	std::map< Glib::ustring, std::vector<Glib::ustring> > & map )
 {
 	std::string line ;
-	char node[4096+1], mountpoint[4096+1] ;
-	unsigned int index ;
+	Glib::ustring node ;
+	Glib::ustring mountpoint ;
 
 	std::ifstream file( filename .c_str() ) ;
 	if ( file )
 	{
 		while ( getline( file, line ) )
-			if ( Glib::str_has_prefix( line, "/" ) &&
-			     sscanf( line .c_str(), "%4096s %4096s", node, mountpoint ) == 2 &&
-			     Glib::ustring( node ) != "/dev/root" )
+		{
+			node       = Utils::regexp_label( line, "^(/[^ \t]+)[ \t]+[^ \t]+" ) ;
+			mountpoint = Utils::regexp_label( line, "^/[^ \t]+[ \t]+([^ \t]+)" ) ;
+			if ( mountpoint .length() > 0 &&
+			     node .length() > 0 &&
+			     node != "/dev/root" )
 			{
-				line = mountpoint ;
-
-				//see if mount point contains spaces and deal with it
-				index = line .find( "\\040" ) ;
-				if ( index < line .length() )
-					line .replace( index, 4, " " ) ;
-
 				//only add this path if it exists
-				if ( file_test( line, Glib::FILE_TEST_EXISTS ) )
-					map[ node ] .push_back( line ) ;	
+				if ( file_test( mountpoint, Glib::FILE_TEST_EXISTS ) )
+				{
+					map[ node ] .push_back( mountpoint ) ;
+					//FIXME:  Should check if file is a symbolic link.  If so then find real path
+				}
 			}
+		}
 
 		file .close() ;
 	}



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