[gparted] Handle characters like spaces in mount points (#629592)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Handle characters like spaces in mount points (#629592)
- Date: Thu, 9 Dec 2010 22:00:07 +0000 (UTC)
commit 3973b6961de37beab359d72236feadbd1b912bb1
Author: Curtis Gedak <gedakc gmail com>
Date: Thu Dec 9 13:59:33 2010 -0700
Handle characters like spaces in mount points (#629592)
Use mntent C library to read mount point files such as
/etc/fstab, /etc/mtab, and /proc/mounts.
Closes bug #629592 - Unable to find Mount Point if it contains a
Space Character
src/GParted_Core.cc | 50 ++++++++++++++++++++++++++------------------------
1 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index e23deda..b928774 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -52,6 +52,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
+#include <mntent.h>
std::vector<Glib::ustring> libparted_messages ; //see ped_exception_handler()
@@ -748,39 +749,40 @@ void GParted_Core::read_mountpoints_from_file(
const Glib::ustring & filename,
std::map< Glib::ustring, std::vector<Glib::ustring> > & map )
{
- std::string line ;
- Glib::ustring node ;
- Glib::ustring mountpoint ;
+ FILE* fp = setmntent( filename .c_str(), "r" ) ;
- std::ifstream file( filename .c_str() ) ;
- if ( file )
+ if ( fp == NULL )
+ return ;
+
+ struct mntent* p = NULL ;
+
+ while ( (p = getmntent(fp)) != NULL )
{
- while ( getline( file, line ) )
+ Glib::ustring node = p->mnt_fsname ;
+
+ if ( ! node .empty() )
{
- node = Utils::regexp_label( line, "^(/[^ \t]+)[ \t]+[^ \t]+" ) ;
- mountpoint = Utils::regexp_label( line, "^/[^ \t]+[ \t]+([^ \t]+)" ) ;
- if ( mountpoint .length() > 0 && node .length() > 0 )
+ Glib::ustring mountpoint = p->mnt_dir ;
+
+ //Only add node path(s) if mount point exists
+ if ( file_test( mountpoint, Glib::FILE_TEST_EXISTS ) )
{
- //Only add node path(s) if mount point exists
- if ( file_test( mountpoint, Glib::FILE_TEST_EXISTS ) )
- {
- map[ node ] .push_back( mountpoint ) ;
+ map[ node ] .push_back( mountpoint ) ;
- //If node is a symbolic link (e.g., /dev/root)
- // then find real path and add entry
- if ( file_test( node, Glib::FILE_TEST_IS_SYMLINK ) )
- {
- char c_str[4096+1] ;
- //FIXME: it seems realpath is very unsafe to use (manpage)...
- if ( realpath( node .c_str(), c_str ) != NULL )
- map[ c_str ] .push_back( mountpoint ) ;
- }
+ //If node is a symbolic link (e.g., /dev/root)
+ // then find real path and add entry
+ if ( file_test( node, Glib::FILE_TEST_IS_SYMLINK ) )
+ {
+ char c_str[4096+1] ;
+ //FIXME: it seems realpath is very unsafe to use (manpage)...
+ if ( realpath( node .c_str(), c_str ) != NULL )
+ map[ c_str ] .push_back( mountpoint ) ;
}
}
}
-
- file .close() ;
}
+
+ endmntent( fp ) ;
}
void GParted_Core::read_mountpoints_from_file_swaps(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]