1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/SolvIdentFile.cc
15 #include "zypp/base/LogTools.h"
16 #include "zypp/base/IOStream.h"
17 #include "zypp/base/String.h"
19 #include "zypp/PathInfo.h"
20 #include "zypp/TmpPath.h"
21 #include "zypp/Date.h"
23 #include "zypp/target/SolvIdentFile.h"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
34 void SolvIdentFile::load( const Pathname & file_r, Data & data_r )
36 PathInfo pi( file_r );
39 WAR << "Can't read " << pi << endl;
42 std::ifstream infile( file_r.c_str() );
43 for( iostr::EachLine in( infile ); in; in.next() )
45 std::string l( str::trim(*in) );
46 if ( ! l.empty() && l[0] != '#' )
48 data_r.insert( IdString(l) );
51 MIL << "Read " << pi << endl;
54 void SolvIdentFile::store( const Pathname & file_r, const Data & data_r )
56 filesystem::TmpFile tmp( filesystem::TmpFile::makeSibling( file_r ) );
57 filesystem::chmod( tmp.path(), 0644 );
59 std::ofstream outs( tmp.path().c_str() );
60 outs << "# " << file_r.basename() << " generated " << Date::now() << endl;
63 std::set<IdString> sorted( data_r.begin(), data_r.end() );
64 dumpRange( outs, sorted.begin(), sorted.end(), "#", "\n", "\n", "\n", "#\n" );
68 dumpRange( outs, data_r.begin(), data_r.end(), "#", "\n", "\n", "\n", "#\n" );
74 filesystem::rename( tmp.path(), file_r );
75 MIL << "Wrote " << PathInfo(file_r) << endl;
79 ERR << "Can't write " << PathInfo(tmp.path()) << endl;
83 /******************************************************************
85 ** FUNCTION NAME : operator<<
86 ** FUNCTION TYPE : std::ostream &
88 std::ostream & operator<<( std::ostream & str, const SolvIdentFile & obj )
90 str << obj.file() << ' ';
98 /////////////////////////////////////////////////////////////////
100 ///////////////////////////////////////////////////////////////////
101 /////////////////////////////////////////////////////////////////
103 ///////////////////////////////////////////////////////////////////