Author: aschnell
Date: Thu Mar 26 14:27:01 2009
New Revision: 56426
URL: http://svn.opensuse.org/viewcvs/yast?rev=56426&view=rev
Log:
- some refactoring
Modified:
trunk/storage/libstorage/src/AppUtil.cc
trunk/storage/libstorage/src/AppUtil.h
trunk/storage/libstorage/src/ProcMounts.cc
trunk/storage/libstorage/src/Storage.cc
Modified: trunk/storage/libstorage/src/AppUtil.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AppUtil.cc?rev=56426&r1=56425&r2=56426&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AppUtil.cc (original)
+++ trunk/storage/libstorage/src/AppUtil.cc Thu Mar 26 14:27:01 2009
@@ -395,29 +395,31 @@
}
-void
-getUdevMap(const char* path, map& m)
+map
+getUdevMap(const char* path)
{
- y2mil( "path: " << path );
+ y2mil("path: " << path);
- map links = getUdevLinks(path);
+ const map links = getUdevLinks(path);
- m.clear();
- for (map::const_iterator it = links.begin(); it != links.end(); it++)
- m[it->second].push_back(it->first);
+ map ret;
+ for (map::const_iterator it = links.begin(); it != links.end(); ++it)
+ ret[it->second].push_back(it->first);
- y2mil("map: " << m);
+ y2mil("map: " << ret);
+ return ret;
}
-void
-getRevUdevMap(const char* path, map& m)
+map
+getRevUdevMap(const char* path)
{
y2mil("path: " << path);
- m = getUdevLinks(path);
+ map ret = getUdevLinks(path);
- y2mil("map: " << m);
+ y2mil("map: " << ret);
+ return ret;
}
Modified: trunk/storage/libstorage/src/AppUtil.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AppUtil.h?rev=56426&r1=56425&r2=56426&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AppUtil.h (original)
+++ trunk/storage/libstorage/src/AppUtil.h Thu Mar 26 14:27:01 2009
@@ -12,6 +12,8 @@
namespace storage
{
using std::string;
+ using std::list;
+ using std::map;
void createPath(const string& Path_Cv);
@@ -26,8 +28,8 @@
const string& delim = "=",
const string& removeSur = " \t\n" );
-void getUdevMap(const char* path, std::map& m);
-void getRevUdevMap(const char* path, std::map& m);
+ map getUdevMap(const char* path);
+ map getRevUdevMap(const char* path);
string normalizeDevice( const string& dev );
void normalizeDevice( string& dev );
Modified: trunk/storage/libstorage/src/ProcMounts.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/ProcMounts.cc?rev=56426&r1=56425&r2=56426&view=diff
==============================================================================
--- trunk/storage/libstorage/src/ProcMounts.cc (original)
+++ trunk/storage/libstorage/src/ProcMounts.cc Thu Mar 26 14:27:01 2009
@@ -20,10 +20,8 @@
ProcMounts::ProcMounts( Storage * const sto )
{
- map by_label;
- map by_uuid;
- getRevUdevMap("/dev/disk/by-label", by_label);
- getRevUdevMap("/dev/disk/by-uuid", by_uuid);
+ const map by_label = getRevUdevMap("/dev/disk/by-label");
+ const map by_uuid = getRevUdevMap("/dev/disk/by-uuid");
ifstream mounts( "/proc/mounts" );
classic(mounts);
string line;
@@ -32,24 +30,26 @@
while( mounts.good() )
{
string dev = extractNthWord( 0, line );
- if( dev.find( "/by-label/" ) != string::npos )
+ if (boost::contains(dev, "/by-label/"))
{
dev = dev.substr( dev.rfind( "/" )+1 );
y2mil( "dev:" << dev );
- if( !by_label[dev].empty() )
- {
- dev = by_label[dev];
+ map::const_iterator it = by_label.find(dev);
+ if (it != by_label.end())
+ {
+ dev = it->second;
normalizeDevice( dev );
y2mil( "dev:" << dev );
}
}
- else if( dev.find( "/by-uuid/" ) != string::npos )
+ else if (boost::contains(dev, "/by-uuid/"))
{
dev = dev.substr( dev.rfind( "/" )+1 );
y2mil( "dev:" << dev );
- if( !by_uuid[dev].empty() )
+ map::const_iterator it = by_uuid.find(dev);
+ if (it != by_uuid.end())
{
- dev = by_uuid[dev];
+ dev = it->second;
normalizeDevice( dev );
y2mil( "dev:" << dev );
}
Modified: trunk/storage/libstorage/src/Storage.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Storage.cc?rev=56426&r1=56425&r2=56426&view=diff
==============================================================================
--- trunk/storage/libstorage/src/Storage.cc (original)
+++ trunk/storage/libstorage/src/Storage.cc Thu Mar 26 14:27:01 2009
@@ -502,16 +502,15 @@
DmraidCo::getRaids(l);
if (!l.empty())
{
- map by_id;
- getUdevMap("/dev/disk/by-id", by_id);
+ const map by_id = getUdevMap("/dev/disk/by-id");
for( list<string>::const_iterator i=l.begin(); i!=l.end(); ++i )
{
DmraidCo * v = new DmraidCo( this, *i, ppart );
if( v->isValid() )
{
- list<string> nm = by_id["dm-"+decString(v->minorNr())];
- if( !nm.empty() )
- v->setUdevData( nm );
+ map::const_iterator it = by_id.find("dm-" + decString(v->minorNr()));
+ if (it != by_id.end())
+ v->setUdevData(it->second);
addToList( v );
}
else
@@ -545,16 +544,15 @@
DmmultipathCo::getMultipaths(l);
if (!l.empty())
{
- map by_id;
- getUdevMap("/dev/disk/by-id", by_id);
+ const map by_id = getUdevMap("/dev/disk/by-id");
for( list<string>::const_iterator i=l.begin(); i!=l.end(); ++i )
{
DmmultipathCo * v = new DmmultipathCo( this, *i, ppart );
if( v->isValid() )
{
- list<string> nm = by_id["dm-"+decString(v->minorNr())];
- if (!nm.empty())
- v->setUdevData( nm );
+ map::const_iterator it = by_id.find("dm-" + decString(v->minorNr()));
+ if (it != by_id.end())
+ v->setUdevData(it->second);
addToList( v );
}
else
@@ -675,10 +673,8 @@
struct dirent *Entry;
if( (Dir=opendir(SYSFSDIR))!=NULL )
{
- map by_path;
- map by_id;
- getUdevMap("/dev/disk/by-path", by_path);
- getUdevMap("/dev/disk/by-id", by_id);
+ const map by_path = getUdevMap("/dev/disk/by-path");
+ const map by_id = getUdevMap("/dev/disk/by-id");
list<DiskData> dl;
while( (Entry=readdir( Dir ))!=NULL )
{
@@ -739,10 +735,17 @@
{
if( i->d )
{
- string tmp;
- if (!by_path[i->dev].empty())
- tmp = by_path[i->dev].front();
- i->d->setUdevData(tmp, by_id[i->dev]);
+ string tmp1;
+ map::const_iterator it1 = by_path.find(i->dev);
+ if (it1 != by_path.end())
+ tmp1 = it1->second.front();
+
+ list<string> tmp2;
+ map::const_iterator it2 = by_id.find(i->dev);
+ if (it2 != by_id.end())
+ tmp2 = it2->second;
+
+ i->d->setUdevData(tmp1, tmp2);
addToList( i->d );
}
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org