1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/HardLocksFile.h
12 #ifndef ZYPP_TARGET_HARDLOCKSFILE_H
13 #define ZYPP_TARGET_HARDLOCKSFILE_H
17 #include "zypp/base/PtrTypes.h"
19 #include "zypp/Pathname.h"
20 #include "zypp/pool/PoolTraits.h"
21 #include "zypp/PoolQuery.h"
23 ///////////////////////////////////////////////////////////////////
25 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
32 // CLASS NAME : HardLocksFile
34 /** Save and restore hardlocks.
38 friend std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj );
41 typedef pool::PoolTraits::HardLockQueries Data;
44 /** Ctor taking the file to read/write. */
45 HardLocksFile( const Pathname & file_r )
49 /** Return the file path. */
50 const Pathname & file() const
54 * The file is read once on demand. Returns empty \ref Data if
55 * the file does not exist or is not readable.
57 const Data & data() const
61 _dataPtr.reset( new Data );
62 Data & mydata( *_dataPtr );
63 load( _file, mydata );
68 /** Store new \ref Data.
69 * Write the new \ref Data to file, unless we know it
70 * did not change. The directory containing file must
73 void setData( const Data & data_r )
78 return; // bsc#1096803: Prevent against empty commit without Target having been been loaded (!_dataPtr )
79 _dataPtr.reset( new Data );
82 if ( differs( *_dataPtr, data_r ) )
84 store( _file, data_r );
90 /** Helper testing whether two \ref Data differ. */
91 bool differs( const Data & lhs, const Data & rhs ) const
93 if ( lhs.size() != rhs.size() )
95 // Complete diff is too expensive and not necessary here.
96 // Just check for the same sequence of items.
97 Data::const_iterator rit = rhs.begin();
98 for_( it, lhs.begin(), lhs.end() )
106 /** Read \ref Data from \c file_r. */
107 static void load( const Pathname & file_r, Data & data_r );
108 /** Write \ref Data to \c file_r. */
109 static void store( const Pathname & file_r, const Data & data_r );
113 mutable scoped_ptr<Data> _dataPtr;
115 ///////////////////////////////////////////////////////////////////
117 /** \relates HardLocksFile Stream output */
118 std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj );
120 /////////////////////////////////////////////////////////////////
121 } // namespace target
122 ///////////////////////////////////////////////////////////////////
123 /////////////////////////////////////////////////////////////////
125 ///////////////////////////////////////////////////////////////////
126 #endif // ZYPP_TARGET_HARDLOCKSFILE_H