libzypp  13.10.6
HardLocksFile.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <fstream>
14 
15 #include "zypp/base/LogTools.h"
16 #include "zypp/base/IOStream.h"
17 #include "zypp/base/String.h"
18 
19 #include "zypp/PathInfo.h"
20 #include "zypp/TmpPath.h"
21 #include "zypp/Date.h"
22 
24 #include "zypp/PoolQueryUtil.tcc"
25 
26 using std::endl;
27 
29 namespace zypp
30 {
31  namespace target
33  {
34 
35  void HardLocksFile::load( const Pathname & file_r, Data & data_r )
36  {
37  PathInfo pi( file_r );
38  if ( ! pi.isFile() )
39  {
40  WAR << "Can't read " << pi << endl;
41  return;
42  }
43 
44  readPoolQueriesFromFile( file_r, std::back_inserter( data_r ) );
45 
46  MIL << "Read " << pi << endl;
47  }
48 
49  void HardLocksFile::store( const Pathname & file_r, const Data & data_r )
50  {
52  filesystem::chmod( tmp.path(), 0644 );
53 
54  writePoolQueriesToFile( tmp.path(), data_r.begin(), data_r.end() );
55 
56  if ( true ) // by now: no error info from writePoolQueriesToFile
57  {
58  filesystem::rename( tmp.path(), file_r );
59  MIL << "Wrote " << PathInfo(file_r) << endl;
60  }
61  else
62  {
63  ERR << "Can't write " << PathInfo(tmp.path()) << endl;
64  }
65  }
66 
67  /******************************************************************
68  **
69  ** FUNCTION NAME : operator<<
70  ** FUNCTION TYPE : std::ostream &
71  */
72  std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj )
73  {
74  str << obj.file() << ' ';
75  if ( obj._dataPtr )
76  str << obj.data();
77  else
78  str << "(unloaded)";
79  return str;
80  }
81 
83  } // namespace target
86 } // namespace zypp
#define MIL
Definition: Logger.h:47
Pathname path() const
Definition: TmpPath.cc:146
const Data & data() const
Return the data.
Definition: HardLocksFile.h:57
void readPoolQueriesFromFile(const zypp::filesystem::Pathname &file, OutputIterator out)
sends to output iterator all queries readed from file.
int chmod(const Pathname &path, mode_t mode)
Like &#39;chmod&#39;.
Definition: PathInfo.cc:1021
static void store(const Pathname &file_r, const Data &data_r)
Write Data to file_r.
Provide a new empty temporary file and delete it when no longer needed.
Definition: TmpPath.h:126
#define ERR
Definition: Logger.h:49
static void load(const Pathname &file_r, Data &data_r)
Read Data from file_r.
int rename(const Pathname &oldpath, const Pathname &newpath)
Like &#39;rename&#39;.
Definition: PathInfo.cc:674
#define WAR
Definition: Logger.h:48
including fstream is not hell here because this header only included by implementation file...
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
void writePoolQueriesToFile(const zypp::filesystem::Pathname &file, InputIterator begin, InputIterator end)
Writes all queries from begin to end.
pool::PoolTraits::HardLockQueries Data
Definition: HardLocksFile.h:41
static TmpFile makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition: TmpPath.cc:218
Save and restore hardlocks.
Definition: HardLocksFile.h:36
const Pathname & file() const
Return the file path.
Definition: HardLocksFile.h:50
scoped_ptr< Data > _dataPtr