Author: aschnell
Date: Tue Aug 19 16:29:00 2008
New Revision: 50211
URL: http://svn.opensuse.org/viewcvs/yast?rev=50211&view=rev
Log:
- don't use external programs to get udev links (now also works with spaces) (for bug #396732)
Modified:
trunk/storage/libstorage/src/AppUtil.cc
Modified: trunk/storage/libstorage/src/AppUtil.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AppUtil.cc?rev=50211&r1=50210&r2=50211&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AppUtil.cc (original)
+++ trunk/storage/libstorage/src/AppUtil.cc Tue Aug 19 16:29:00 2008
@@ -7,8 +7,8 @@
#include
#include <string>
#include
-#include
-#include
+#include
+#include
#include <locale>
#include
@@ -416,85 +416,75 @@
}
-void
-getFindMap(const char* path, map& m)
+int
+readlink(const char* path, string& buf)
{
- y2mil( "path: " << path);
- m.clear();
- if( access( path, R_OK )==0 )
+ const int size = 1024;
+ char tmp[size];
+ int ret = ::readlink(path, tmp, size);
+ if (ret >= 0)
+ buf = string(tmp, ret);
+ return ret;
+}
+
+
+map
+getUdevLinks(const char* path)
{
- string cmd = "/usr/bin/find ";
- cmd += path;
- cmd += " -type l -printf '%f %l\n'";
- SystemCmd findcmd( cmd.c_str() );
- list<string> l;
- findcmd.getStdout( l );
- list<string>::iterator i=l.begin();
- while( i!=l.end() )
+ map links;
+
+ DIR* dir;
+ if ((dir = opendir(path)) != NULL)
{
- list<string> tlist = splitString( *i );
- if( tlist.size()==2 )
+ struct dirent* entry;
+ while ((entry = readdir(dir)) != NULL)
{
- string& tmp = tlist.back();
- string dsk = tmp.substr( tmp.find_first_not_of( "./" ) );
- m[dsk].push_back(tlist.front());
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+ continue;
+
+ string full = string(path) + "/" + entry->d_name;
+
+ string tmp;
+ if (readlink(full.c_str(), tmp) != -1)
+ {
+ string::size_type pos = tmp.find_last_of('/');
+ if (pos == string::npos)
+ links[entry->d_name] = tmp;
+ else
+ links[entry->d_name] = tmp.substr(pos + 1);
}
- ++i;
}
+ closedir(dir);
}
- y2mil( "map: " << m );
+
+ return links;
}
-void getFindRevMap( const char* path, map& ret )
+
+void
+getFindMap(const char* path, map& m)
{
y2mil( "path: " << path );
- map m;
- if( access( path, R_OK )==0 )
- {
- string cmd = "/bin/ls -lt ";
- cmd += path;
- SystemCmd findcmd( cmd.c_str() );
- list<string> l;
- findcmd.getStdout( l );
- list<string>::iterator i=l.begin();
- while( i!=l.end() )
- {
- list<string> tlist = splitString( *i );
- string dev, id;
- y2mil( "tlist:" << tlist );
- if( !tlist.empty() )
- {
- dev = tlist.back();
- tlist.pop_back();
- dev.erase( 0, dev.find_first_not_of( "./" ) );
- if( !tlist.empty() && tlist.back() == "->" )
- {
- tlist.pop_back();
- if( !tlist.empty() )
- id = tlist.back();
+
+ map links = getUdevLinks(path);
+
+ m.clear();
+ for (map::const_iterator it = links.begin(); it != links.end(); it++)
+ m[it->second].push_back(it->first);
+
+ y2mil("map: " << m);
}
- if( !id.empty() && !dev.empty() )
+
+void
+getFindRevMap(const char* path, map& m)
{
- map::iterator mi = m.find( dev );
- if( mi == m.end() )
- {
- m[dev] = id;
+ y2mil("path: " << path);
+
+ m = getUdevLinks(path);
+
+ y2mil("map: " << m);
}
- else
- y2mil( "already here dev:" << mi->first <<
- " id:" << mi->second );
- }
- }
- ++i;
- }
- ret.clear();
- for( map::iterator mi = m.begin(); mi!=m.end(); ++mi )
- {
- ret[mi->second] = mi->first;
- }
- }
- y2mil( "map: " << ret );
- }
+
unsigned getMajorDevices( const string& driver )
{
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org