![](https://seccdn.libravatar.org/avatar/8a451195df9bfe79b11fe6fa7da429d7.jpg?s=120&d=mm&r=g)
Author: mvidner Date: Tue Nov 8 16:15:59 2011 New Revision: 66759 URL: http://svn.opensuse.org/viewcvs/yast?rev=66759&view=rev Log: Factored out IniParser::write_file Modified: branches/SuSE-Code-11-SP2-Branch/core/agent-ini/src/IniParser.cc branches/SuSE-Code-11-SP2-Branch/core/agent-ini/src/IniParser.h Modified: branches/SuSE-Code-11-SP2-Branch/core/agent-ini/src/IniParser.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/core/a... ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/core/agent-ini/src/IniParser.cc (original) +++ branches/SuSE-Code-11-SP2-Branch/core/agent-ini/src/IniParser.cc Tue Nov 8 16:15:59 2011 @@ -965,19 +965,7 @@ continue; } s.initReadBy (); - // ensure that the directories exist - Pathname pn (filename); - PathInfo::assert_dir (pn.dirname ()); - ofstream of(filename.c_str()); - if (!of.good()) - { - bugs++; - y2error ("Can not open file %s for write", filename.c_str()); - continue; - } - write_helper (s, of, 0); - s.clean(); - of.close (); + bugs += write_file(filename, s); } else { @@ -997,24 +985,30 @@ } else { - // ensure that the directories exist - Pathname pn (file); - PathInfo::assert_dir (pn.dirname ()); - ofstream of(file.c_str()); - if (!of.good()) - { - y2error ("Can not open file %s for write", file.c_str()); - return -1; - } - - write_helper (inifile, of, 0); - - of.close(); + bugs += write_file(file, inifile); timestamp = getTimeStamp (); } - inifile.clean (); return bugs ? -1 : 0; } + +// return 0 on success, like write +int IniParser::write_file(const string & filename, IniSection & section) +{ + // ensure that the directories exist + Pathname pn(filename); + PathInfo::assert_dir (pn.dirname ()); + ofstream of(filename.c_str()); + if (!of.good()) { + y2error ("Can not open file %s for write", filename.c_str()); + return -1; + } + + write_helper (section, of, 0); + + of.close(); + return 0; +} + int IniParser::write_helper(IniSection&ini, ofstream&of, int depth) { char out_buffer[2048]; Modified: branches/SuSE-Code-11-SP2-Branch/core/agent-ini/src/IniParser.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/core/a... ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/core/agent-ini/src/IniParser.h (original) +++ branches/SuSE-Code-11-SP2-Branch/core/agent-ini/src/IniParser.h Tue Nov 8 16:15:59 2011 @@ -372,6 +372,10 @@ /** * Write one ini file. */ + int write_file(const string & filename, IniSection & section); + /** + * Write one ini file. + */ int write_helper(IniSection&ini, ofstream&of,int depth); public: /** -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org