libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 #include <fstream> 00014 00015 #include "zypp/base/LogTools.h" 00016 #include "zypp/base/IOStream.h" 00017 #include "zypp/base/String.h" 00018 00019 #include "zypp/PathInfo.h" 00020 #include "zypp/TmpPath.h" 00021 #include "zypp/Date.h" 00022 00023 #include "zypp/target/HardLocksFile.h" 00024 #include "zypp/PoolQueryUtil.tcc" 00025 00026 using std::endl; 00027 00029 namespace zypp 00030 { 00031 00032 namespace target 00033 { 00034 00035 void HardLocksFile::load( const Pathname & file_r, Data & data_r ) 00036 { 00037 PathInfo pi( file_r ); 00038 if ( ! pi.isFile() ) 00039 { 00040 WAR << "Can't read " << pi << endl; 00041 return; 00042 } 00043 00044 readPoolQueriesFromFile( file_r, std::back_inserter( data_r ) ); 00045 00046 MIL << "Read " << pi << endl; 00047 } 00048 00049 void HardLocksFile::store( const Pathname & file_r, const Data & data_r ) 00050 { 00051 filesystem::TmpFile tmp( filesystem::TmpFile::makeSibling( file_r ) ); 00052 filesystem::chmod( tmp.path(), 0644 ); 00053 00054 writePoolQueriesToFile( tmp.path(), data_r.begin(), data_r.end() ); 00055 00056 if ( true ) // by now: no error info from writePoolQueriesToFile 00057 { 00058 filesystem::rename( tmp.path(), file_r ); 00059 MIL << "Wrote " << PathInfo(file_r) << endl; 00060 } 00061 else 00062 { 00063 ERR << "Can't write " << PathInfo(tmp.path()) << endl; 00064 } 00065 } 00066 00067 /****************************************************************** 00068 ** 00069 ** FUNCTION NAME : operator<< 00070 ** FUNCTION TYPE : std::ostream & 00071 */ 00072 std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj ) 00073 { 00074 str << obj.file() << ' '; 00075 if ( obj._dataPtr ) 00076 str << obj.data(); 00077 else 00078 str << "(unloaded)"; 00079 return str; 00080 } 00081 00083 } // namespace target 00086 } // namespace zypp