1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoStatus.cc
14 //#include "zypp/base/Logger.h"
15 #include "zypp/RepoStatus.h"
16 #include "zypp/PathInfo.h"
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
26 // CLASS NAME : RepoStatus::Impl
28 /** RepoStatus implementation. */
29 struct RepoStatus::Impl
37 /** Offer default Impl. */
38 static shared_ptr<Impl> nullimpl()
40 static shared_ptr<Impl> _nullimpl( new Impl );
45 friend Impl * rwcowClone<Impl>( const Impl * rhs );
46 /** clone for RWCOW_pointer */
48 { return new Impl( *this ); }
50 ///////////////////////////////////////////////////////////////////
52 /** \relates RepoStatus::Impl Stream output */
53 inline std::ostream & operator<<( std::ostream & str, const RepoStatus::Impl & obj )
55 return str << "RepoStatus::Impl";
58 ///////////////////////////////////////////////////////////////////
60 // CLASS NAME : RepoStatus
62 ///////////////////////////////////////////////////////////////////
64 ///////////////////////////////////////////////////////////////////
66 // METHOD NAME : RepoStatus::RepoStatus
69 RepoStatus::RepoStatus()
70 : _pimpl( new Impl() )
73 ///////////////////////////////////////////////////////////////////
75 // METHOD NAME : RepoStatus::~RepoStatus
78 RepoStatus::~RepoStatus()
81 RepoStatus::RepoStatus( const Pathname &path )
82 : _pimpl( new Impl() )
87 _pimpl->checksum = filesystem::sha1sum(path);
88 _pimpl->timestamp = Date(info.mtime());
92 bool RepoStatus::empty() const
94 return _pimpl->checksum.empty();
97 RepoStatus & RepoStatus::setChecksum( const string &checksum )
99 _pimpl->checksum = checksum;
103 RepoStatus & RepoStatus::setTimestamp( const Date ×tamp )
105 _pimpl->timestamp = timestamp;
109 string RepoStatus::checksum() const
110 { return _pimpl->checksum; }
112 Date RepoStatus::timestamp() const
113 { return _pimpl->timestamp; }
115 RepoStatus operator&&( const RepoStatus &lhs, const RepoStatus &rhs )
118 string combinedcs = (lhs.checksum() + rhs.checksum());
119 stringstream ss(combinedcs);
120 CheckSum newcs(CheckSum::sha1(ss));
121 result.setChecksum(newcs.checksum());
122 result.setTimestamp(lhs.timestamp());
123 if ( rhs.timestamp() > lhs.timestamp() )
124 result.setTimestamp(rhs.timestamp());
128 /******************************************************************
130 ** FUNCTION NAME : operator<<
131 ** FUNCTION TYPE : std::ostream &
133 std::ostream & operator<<( std::ostream & str, const RepoStatus & obj )
135 return str << *obj._pimpl;
138 /////////////////////////////////////////////////////////////////
140 ///////////////////////////////////////////////////////////////////