Author: aschnell
Date: Fri Mar 13 14:24:07 2009
New Revision: 56116
URL: http://svn.opensuse.org/viewcvs/yast?rev=56116&view=rev
Log:
- made filename in AsciiFile const
- handle remove_empty in AsciiFile::save()
- some cleanup
Modified:
trunk/storage/libstorage/src/AsciiFile.cc
trunk/storage/libstorage/src/AsciiFile.h
trunk/storage/libstorage/src/EtcFstab.cc
trunk/storage/libstorage/src/EtcRaidtab.cc
trunk/storage/libstorage/src/EtcRaidtab.h
Modified: trunk/storage/libstorage/src/AsciiFile.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AsciiFile.cc?rev=56116&r1=56115&r2=56116&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AsciiFile.cc (original)
+++ trunk/storage/libstorage/src/AsciiFile.cc Fri Mar 13 14:24:07 2009
@@ -1,5 +1,5 @@
// Maintainer: fehr@suse.de
-/*
+/*
Textdomain "storage"
*/
@@ -16,30 +16,33 @@
using namespace storage;
-AsciiFile::AsciiFile(const char* Name_Cv)
- {
- loadFile( Name_Cv );
- }
+AsciiFile::AsciiFile(const char* Name_Cv, bool remove_empty)
+ : Name_C(Name_Cv),
+ remove_empty(remove_empty)
+{
+ load();
+}
+
+
+AsciiFile::AsciiFile(const string& Name_Cv, bool remove_empty)
+ : Name_C(Name_Cv),
+ remove_empty(remove_empty)
+{
+ load();
+}
-AsciiFile::AsciiFile(const string& Name_Cv)
- {
- loadFile( Name_Cv.c_str() );
- }
AsciiFile::~AsciiFile()
- {
- }
+{
+}
-bool AsciiFile::loadFile( const string& Name_Cv )
- {
- bool Ret_bi;
- y2mil("Loading File:\"" << Name_Cv << "\"");
- Lines_C.clear();
- Ret_bi = appendFile( Name_Cv, Lines_C );
- Name_C = Name_Cv;
- return Ret_bi;
- }
+bool AsciiFile::load()
+{
+ y2mil("loading file " << Name_C);
+ clear();
+ return appendFile( Name_C, Lines_C );
+}
bool AsciiFile::appendFile( const string& Name_Cv )
@@ -130,37 +133,35 @@
return Ret_bi;
}
-bool AsciiFile::updateFile()
- {
- struct stat Stat_ri;
- bool Status_b = stat( Name_C.c_str(), &Stat_ri )==0;
- ofstream File_Ci( Name_C.c_str() );
- classic(File_Ci);
- unsigned int Idx_ii = 0;
+bool
+AsciiFile::save()
+{
+ if (remove_empty && Lines_C.empty())
+ {
+ y2mil("deleting file " << Name_C);
- while( File_Ci.good() && Idx_iihttp://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AsciiFile.h?rev=56116&r1=56115&r2=56116&view=diff
==============================================================================
--- trunk/storage/libstorage/src/AsciiFile.h (original)
+++ trunk/storage/libstorage/src/AsciiFile.h Fri Mar 13 14:24:07 2009
@@ -17,22 +17,24 @@
{
public:
- AsciiFile(const char* Name_Cv);
- AsciiFile(const string& Name_Cv);
+ AsciiFile(const char* name, bool remove_empty = false);
+ AsciiFile(const string& name, bool remove_empty = false);
~AsciiFile();
+ string name() const { return Name_C; }
+
+ bool load();
+ bool save();
+
bool insertFile(const AsciiFile& File_Cv, unsigned int BeforeLine_iv = 0);
bool appendFile(const AsciiFile& File_Cv);
bool insertFile( const string& Name_Cv, unsigned int BeforeLine_iv=0 );
bool appendFile( const string& Name_Cv );
- string fileName() const { return Name_C; }
- bool loadFile( const string& Name_Cv );
- bool updateFile();
-
void append( const string& Line_Cv );
void append( const vector<string>& Lines_Cv );
void insert( unsigned int Before_iv, const string& Line_Cv );
+ void clear();
void remove( unsigned int Start_iv, unsigned int Cnt_iv );
void replace( unsigned int Start_iv, unsigned int Cnt_iv,
const string& Line_Cv );
@@ -53,8 +55,6 @@
unsigned numLines() const { return Lines_C.size(); }
- bool removeIfEmpty() const;
-
const vector<string>& lines() const { return Lines_C; }
protected:
@@ -63,11 +63,14 @@
bool appendFile(const AsciiFile& File_Cv, vector<string>& Lines_Cr) const;
void removeLastIf(string& Text_Cr, char Char_cv) const;
+ const string Name_C;
+ const bool remove_empty;
+
vector<string> Lines_C;
- string Name_C;
};
}
+
#endif
Modified: trunk/storage/libstorage/src/EtcFstab.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/EtcFstab.cc?rev=56116&r1=56115&r2=56116&view=diff
==============================================================================
--- trunk/storage/libstorage/src/EtcFstab.cc (original)
+++ trunk/storage/libstorage/src/EtcFstab.cc Fri Mar 13 14:24:07 2009
@@ -408,7 +408,7 @@
if( e.crypto )
{
if( cryptotab==NULL )
- cryptotab = new AsciiFile( prefix + "/cryptotab" );
+ cryptotab = new AsciiFile( prefix + "/cryptotab", true );
ret = cryptotab;
reg = "[ \t]" + e.dentry + "[ \t]";
}
@@ -426,8 +426,8 @@
int EtcFstab::findPrefix( const AsciiFile& tab, const string& mount )
{
- bool crypto = tab.fileName().find( "/cryptotab" )>=0;
- y2mil( "file:" << tab.fileName() << " mp:" << mount <<
+ bool crypto = tab.name().find( "/cryptotab" )>=0;
+ y2mil( "file:" << tab.name() << " mp:" << mount <<
" crypto:" << crypto );
string reg = "^[ \t]*[^ \t]+";
if( crypto )
@@ -667,7 +667,7 @@
AsciiFile *fstab = NULL;
AsciiFile *cryptotab = NULL;
AsciiFile *cur = NULL;
- AsciiFile crypttab( prefix + "/crypttab" );
+ AsciiFile crypttab( prefix + "/crypttab", true );
int lineno;
if( i!=co.end() && !checkDir( prefix ) )
createPath( prefix );
@@ -785,17 +785,18 @@
}
if( fstab != NULL )
{
- fstab->updateFile();
+ fstab->save();
delete( fstab );
}
if( cryptotab != NULL )
{
- if( !cryptotab->removeIfEmpty() )
- cryptotab->updateFile();
+ cryptotab->save();
delete( cryptotab );
}
- if( !crypttab.removeIfEmpty() )
- crypttab.updateFile();
+ if( true )
+ {
+ crypttab.save();
+ }
printFile( prefix + "/fstab" );
printFile( prefix + "/cryptotab" );
printFile( prefix + "/crypttab" );
@@ -867,7 +868,6 @@
}
-
unsigned EtcFstab::fstabFields[] = { 20, 20, 10, 21, 1, 1 };
unsigned EtcFstab::cryptotabFields[] = { 11, 15, 20, 10, 10, 1 };
unsigned EtcFstab::crypttabFields[] = { 15, 20, 10, 1 };
Modified: trunk/storage/libstorage/src/EtcRaidtab.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/EtcRaidtab.cc?rev=56116&r1=56115&r2=56116&view=diff
==============================================================================
--- trunk/storage/libstorage/src/EtcRaidtab.cc (original)
+++ trunk/storage/libstorage/src/EtcRaidtab.cc Fri Mar 13 14:24:07 2009
@@ -14,18 +14,19 @@
using namespace std;
using namespace storage;
-EtcRaidtab::EtcRaidtab( const string& prefix )
- {
+
+EtcRaidtab::EtcRaidtab(const string& prefix)
+ : mdadm(prefix + "/etc/mdadm.conf")
+{
mdadm_dev_line = -1;
- mdadmname = prefix+"/etc/mdadm.conf";
- mdadm = new AsciiFile( mdadmname );
buildMdadmMap();
- }
+}
+
EtcRaidtab::~EtcRaidtab()
- {
- delete mdadm;
- }
+{
+}
+
void
EtcRaidtab::updateEntry( unsigned num, const list<string>& entries,
@@ -36,22 +37,22 @@
map::iterator i = mtab.find( num );
if( i != mtab.end() )
{
- mdadm->replace( i->second.first, i->second.last-i->second.first+1, mline );
+ mdadm.replace( i->second.first, i->second.last-i->second.first+1, mline );
}
else
{
- mdadm->append( mline );
+ mdadm.append( mline );
}
if( mdadm_dev_line<0 )
{
dline = "DEVICE partitions";
- mdadm_dev_line = mdadm->numLines();
- mdadm->insert( 0, dline );
+ mdadm_dev_line = mdadm.numLines();
+ mdadm.insert( 0, dline );
}
else
{
dline = "DEVICE partitions";
- (*mdadm)[mdadm_dev_line] = dline;
+ mdadm[mdadm_dev_line] = dline;
}
updateMdadmFile();
}
@@ -62,7 +63,7 @@
map::iterator i = mtab.find( num );
if( i != mtab.end() )
{
- mdadm->remove( i->second.first, i->second.last-i->second.first+1 );
+ mdadm.remove( i->second.first, i->second.last-i->second.first+1 );
updateMdadmFile();
}
}
@@ -71,8 +72,7 @@
EtcRaidtab::updateMdadmFile()
{
mtab.clear();
- mdadm->updateFile();
- mdadm->loadFile( mdadmname );
+ mdadm.save();
buildMdadmMap();
}
@@ -83,20 +83,20 @@
unsigned mdnum;
mdadm_dev_line = -1;
entry e;
- while( lineno<mdadm->numLines() )
+ while (lineno < mdadm.numLines())
{
- string key = extractNthWord( 0, (*mdadm)[lineno] );
+ string key = extractNthWord( 0, mdadm[lineno] );
if( mdadm_dev_line<0 && key == "DEVICE" )
mdadm_dev_line = lineno;
else if( key == "ARRAY" &&
- Md::mdStringNum( extractNthWord( 1, (*mdadm)[lineno] ), mdnum ))
+ Md::mdStringNum( extractNthWord( 1, mdadm[lineno] ), mdnum ))
{
e.first = lineno++;
- while( lineno<mdadm->numLines() &&
- (key = extractNthWord( 0, (*mdadm)[lineno] ))!="ARRAY" &&
+ while( lineno < mdadm.numLines() &&
+ (key = extractNthWord( 0, mdadm[lineno] ))!="ARRAY" &&
key != "DEVICE" )
{
- key = extractNthWord( 0, (*mdadm)[lineno++] );
+ key = extractNthWord( 0, mdadm[lineno++] );
}
e.last = lineno-1;
mtab[mdnum] = e;
Modified: trunk/storage/libstorage/src/EtcRaidtab.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/EtcRaidtab.h?rev=56116&r1=56115&r2=56116&view=diff
==============================================================================
--- trunk/storage/libstorage/src/EtcRaidtab.h (original)
+++ trunk/storage/libstorage/src/EtcRaidtab.h Fri Mar 13 14:24:07 2009
@@ -4,11 +4,12 @@
#include <string>
#include <map>
+#include "y2storage/AsciiFile.h"
+
+
namespace storage
{
-class AsciiFile;
-
class EtcRaidtab
{
public:
@@ -31,10 +32,9 @@
void updateMdadmFile();
void buildMdadmMap();
- string mdadmname;
int mdadm_dev_line;
std::map mtab;
- AsciiFile* mdadm;
+ AsciiFile mdadm;
};
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org