libzypp: zypp/target/HardLocksFile.h Source File

libzypp 17.25.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
17 #include <zypp/base/PtrTypes.h>
18
19 #include <zypp/Pathname.h>
20 #include <zypp/pool/PoolTraits.h>
21 #include <zypp/PoolQuery.h>
22
24 namespace zypp
25 {
27 namespace target
28 {
29
31 //
32 // CLASS NAME : HardLocksFile
33 //
36 class HardLocksFile
37 {
38 friend std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj );
39 public:
40
41 typedef pool::PoolTraits::HardLockQueries Data;
42
43 public:
45 HardLocksFile( const Pathname & file_r )
46 : _file( file_r )
47 {}
48
50 const Pathname & file() const
51 { return _file; }
52
57 const Data & data() const
58 {
59 if ( !_dataPtr )
60 {
61 _dataPtr.reset( new Data );
62 Data & mydata( *_dataPtr );
63 load( _file, mydata );
64 }
65 return *_dataPtr;
66 }
67
73 void setData( const Data & data_r )
74 {
75 if ( !_dataPtr )
76 {
77 if ( data_r.empty() )
78 return; // bsc#1096803: Prevent against empty commit without Target having been been loaded (!_dataPtr )
79 _dataPtr.reset( new Data );
80 }
81
82 if ( differs( *_dataPtr, data_r ) )
83 {
84 store( _file, data_r );
85 *_dataPtr = data_r;
86 }
87 }
88
89 private:
91 bool differs( const Data & lhs, const Data & rhs ) const
92 {
93 if ( lhs.size() != rhs.size() )
94 return true;
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() )
99 {
100 if ( *it != *rit )
101 return true;
102 ++rit;
103 }
104 return false;
105 }
107 static void load( const Pathname & file_r, Data & data_r );
109 static void store( const Pathname & file_r, const Data & data_r );
110
111 private:
112 Pathname _file;
113 mutable scoped_ptr<Data> _dataPtr;
114 };
116
118 std::ostream & operator<<( std::ostream & str, const HardLocksFile & obj );
119
121 } // namespace target
124 } // namespace zypp
126 #endif // ZYPP_TARGET_HARDLOCKSFILE_H
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
Pathname.h
PoolQuery.h
PoolTraits.h
PtrTypes.h
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::target::HardLocksFile
Save and restore hardlocks.
Definition: HardLocksFile.h:37
zypp::target::HardLocksFile::setData
void setData(const Data &data_r)
Store new Data.
Definition: HardLocksFile.h:73
zypp::target::HardLocksFile::differs
bool differs(const Data &lhs, const Data &rhs) const
Helper testing whether two Data differ.
Definition: HardLocksFile.h:91
zypp::target::HardLocksFile::operator<<
friend std::ostream & operator<<(std::ostream &str, const HardLocksFile &obj)
Definition: HardLocksFile.cc:72
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::data
const Data & data() const
Return the data.
Definition: HardLocksFile.h:57
zypp::target::HardLocksFile::file
const Pathname & file() const
Return the file path.
Definition: HardLocksFile.h:50
zypp::target::HardLocksFile::Data
pool::PoolTraits::HardLockQueries Data
Definition: HardLocksFile.h:41
zypp::target::HardLocksFile::_file
Pathname _file
Definition: HardLocksFile.h:112
zypp::target::HardLocksFile::_dataPtr
scoped_ptr< Data > _dataPtr
Definition: HardLocksFile.h:113
zypp::target::HardLocksFile::HardLocksFile
HardLocksFile(const Pathname &file_r)
Ctor taking the file to read/write.
Definition: HardLocksFile.h:45
str
String related utilities and Regular expression matching.
zypp::target::operator<<
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Definition: CommitPackageCache.cc:156
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::pool::PoolTraits::HardLockQueries
std::list< PoolQuery > HardLockQueries
hard locks from etc/zypp/locks
Definition: PoolTraits.h:88