libzypp: zypp/target/HardLocksFile.cc Source File

libzypp 17.38.11

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-core/base/LogTools.h>
16#include <zypp-core/base/IOStream.h>
17#include <zypp-core/base/String.h>
18
19#include <zypp/PathInfo.h>
20#include <zypp/TmpPath.h>
21#include <zypp-core/Date.h>
22
23#include <zypp/target/HardLocksFile.h>
24#include <zypp/PoolQueryUtil.tcc>
25
26using std::endl;
27
29namespace zypp
30{
32 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 {
51 filesystem::TmpFile tmp( filesystem::TmpFile::makeSibling( file_r ) );
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
Date.h
HardLocksFile.h
IOStream.h
LogTools.h
MIL
#define MIL
Definition Logger.h:103
ERR
#define ERR
Definition Logger.h:105
WAR
#define WAR
Definition Logger.h:104
PoolQueryUtil.tcc
String.h
zypp::filesystem::PathInfo
Wrapper class for stat/lstat.
Definition PathInfo.h:226
zypp::filesystem::PathInfo::isFile
bool isFile() const
Definition PathInfo.h:295
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::filesystem::TmpFile
Provide a new empty temporary file and delete it when no longer needed.
Definition TmpPath.h:118
zypp::filesystem::TmpFile::makeSibling
static TmpFile makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition TmpPath.cc:182
zypp::filesystem::TmpPath::path
Pathname path() const
Definition TmpPath.cc:124
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::_dataPtr
scoped_ptr< Data > _dataPtr
Definition HardLocksFile.h:114
str
String related utilities and Regular expression matching.
zypp::filesystem::chmod
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
Definition PathInfo.cc:1111
zypp::filesystem::rename
int rename(const Pathname &oldpath, const Pathname &newpath)
Like 'rename'.
Definition PathInfo.cc:761
zypp::target
Definition KeyRing.h:325
zypp::target::operator<<
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
relates: CommitPackageCache Stream output
Definition CommitPackageCache.cc:155
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
PathInfo.h
TmpPath.h