libzypp 17.37.10

HardLocksFile.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_TARGET_HARDLOCKSFILE_H
13#define ZYPP_TARGET_HARDLOCKSFILE_H
14
15#include <iosfwd>
16#include <utility>
17
18#include <zypp/base/PtrTypes.h>
19
20#include <zypp/Pathname.h>
21#include <zypp/pool/PoolTraits.h>
22#include <zypp/PoolQuery.h>
23
25 namespace zypp
26{
28 namespace target
29 {
30
32 //
33 // CLASS NAME : HardLocksFile
34 //
37 class HardLocksFile
38 {
39 friend std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj );
40 public:
41
42 using Data = pool::PoolTraits::HardLockQueries;
43
44 public:
46 HardLocksFile( Pathname file_r )
47 : _file(std::move( file_r ))
48 {}
49
51 const Pathname & file() const
52 { return _file; }
53
58 const Data & data() const
59 {
60 if ( !_dataPtr )
61 {
62 _dataPtr.reset( new Data );
63 Data & mydata( *_dataPtr );
64 load( _file, mydata );
65 }
66 return *_dataPtr;
67 }
68
74 void setData( const Data & data_r )
75 {
76 if ( !_dataPtr )
77 {
78 if ( data_r.empty() )
79 return; // bsc#1096803: Prevent against empty commit without Target having been been loaded (!_dataPtr )
80 _dataPtr.reset( new Data );
81 }
82
83 if ( differs( *_dataPtr, data_r ) )
84 {
85 store( _file, data_r );
86 *_dataPtr = data_r;
87 }
88 }
89
90 private:
92 bool differs( const Data & lhs, const Data & rhs ) const
93 {
94 if ( lhs.size() != rhs.size() )
95 return true;
96 // Complete diff is too expensive and not necessary here.
97 // Just check for the same sequence of items.
98 Data::const_iterator rit = rhs.begin();
99 for_( it, lhs.begin(), lhs.end() )
100 {
101 if ( *it != *rit )
102 return true;
103 ++rit;
104 }
105 return false;
106 }
107
108 static void load( const Pathname & file_r, Data & data_r );
110 static void store( const Pathname & file_r, const Data & data_r );
111
112 private:
113 Pathname _file;
114 mutable scoped_ptr<Data> _dataPtr;
115 };
116
117
119 std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj );
120
122 } // namespace target
125} // namespace zypp
127#endif // ZYPP_TARGET_HARDLOCKSFILE_H
PoolQuery.h
PoolTraits.h
scoped_ptr
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::target::HardLocksFile
Save and restore hardlocks.
Definition HardLocksFile.h:38
zypp::target::HardLocksFile::setData
void setData(const Data &data_r)
Store new Data.
Definition HardLocksFile.h:74
zypp::target::HardLocksFile::differs
bool differs(const Data &lhs, const Data &rhs) const
Helper testing whether two Data differ.
Definition HardLocksFile.h:92
zypp::target::HardLocksFile::data
const Data & data() const
Return the data.
Definition HardLocksFile.h:58
zypp::target::HardLocksFile::load
static void load(const Pathname &file_r, Data &data_r)
Read Data from file_r.
Definition HardLocksFile.cc:35
zypp::target::HardLocksFile::store
static void store(const Pathname &file_r, const Data &data_r)
Write Data to file_r.
Definition HardLocksFile.cc:49
zypp::target::HardLocksFile::HardLocksFile
HardLocksFile(Pathname file_r)
Ctor taking the file to read/write.
Definition HardLocksFile.h:46
zypp::target::HardLocksFile::Data
pool::PoolTraits::HardLockQueries Data
Definition HardLocksFile.h:42
zypp::target::HardLocksFile::file
const Pathname & file() const
Return the file path.
Definition HardLocksFile.h:51
zypp::target::HardLocksFile::_file
Pathname _file
Definition HardLocksFile.h:113
zypp::target::HardLocksFile::_dataPtr
scoped_ptr< Data > _dataPtr
Definition HardLocksFile.h:114
zypp::target::HardLocksFile::operator<<
friend std::ostream & operator<<(std::ostream &str, const HardLocksFile &obj)
Definition HardLocksFile.cc:72
std
Definition Arch.h:364
str
String related utilities and Regular expression matching.
zypp::target
Definition KeyRing.h:325
zypp::target::operator<<
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Definition CommitPackageCache.cc:160
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::pool::PoolTraits::HardLockQueries
std::list< PoolQuery > HardLockQueries
hard locks from etc/zypp/locks
Definition PoolTraits.h:85
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
Pathname.h
PtrTypes.h