1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoStatus.cc
15 #include "zypp/base/Logger.h"
16 #include "zypp/base/String.h"
17 #include "zypp/RepoStatus.h"
18 #include "zypp/PathInfo.h"
22 ///////////////////////////////////////////////////////////////////
24 { /////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////
28 // CLASS NAME : RepoStatus::Impl
30 /** RepoStatus implementation. */
31 struct RepoStatus::Impl
39 /** Offer default Impl. */
40 static shared_ptr<Impl> nullimpl()
42 static shared_ptr<Impl> _nullimpl( new Impl );
47 friend Impl * rwcowClone<Impl>( const Impl * rhs );
48 /** clone for RWCOW_pointer */
50 { return new Impl( *this ); }
52 ///////////////////////////////////////////////////////////////////
54 /** \relates RepoStatus::Impl Stream output */
55 inline std::ostream & operator<<( std::ostream & str, const RepoStatus::Impl & obj )
57 return str << obj.checksum << " " << (time_t) obj.timestamp;
60 ///////////////////////////////////////////////////////////////////
62 // CLASS NAME : RepoStatus
64 ///////////////////////////////////////////////////////////////////
66 ///////////////////////////////////////////////////////////////////
68 // METHOD NAME : RepoStatus::RepoStatus
71 RepoStatus::RepoStatus()
72 : _pimpl( new Impl() )
75 RepoStatus::RepoStatus( const Pathname &path )
76 : _pimpl( new Impl() )
81 _pimpl->timestamp = Date(info.mtime());
83 _pimpl->checksum = filesystem::sha1sum(path);
85 _pimpl->checksum = str::numstring(info.mtime());
89 ///////////////////////////////////////////////////////////////////
91 // METHOD NAME : RepoStatus::~RepoStatus
94 RepoStatus::~RepoStatus()
97 RepoStatus RepoStatus::fromCookieFile( const Pathname &cookiefile )
99 std::ifstream file(cookiefile.c_str());
101 WAR << "No cookie file " << cookiefile << endl;
108 status.setChecksum(buffer);
110 status.setTimestamp(Date(str::strtonum<time_t>(buffer)));
114 void RepoStatus::saveToCookieFile( const Pathname &cookiefile ) const
116 std::ofstream file(cookiefile.c_str());
118 ZYPP_THROW (Exception( "Can't open " + cookiefile.asString() ) );
120 file << this->checksum() << " " << (int) this->timestamp() << endl << endl;
124 bool RepoStatus::empty() const
126 return _pimpl->checksum.empty();
129 RepoStatus & RepoStatus::setChecksum( const string &checksum )
131 _pimpl->checksum = checksum;
135 RepoStatus & RepoStatus::setTimestamp( const Date ×tamp )
137 _pimpl->timestamp = timestamp;
141 string RepoStatus::checksum() const
142 { return _pimpl->checksum; }
144 Date RepoStatus::timestamp() const
145 { return _pimpl->timestamp; }
147 RepoStatus operator&&( const RepoStatus & lhs, const RepoStatus & rhs )
154 std::string lchk( lhs.checksum() );
155 std::string rchk( rhs.checksum() );
156 // order strings to assert && is kommutativ
157 stringstream ss( lchk < rchk ? lchk+rchk : rchk+lchk );
160 result.setChecksum( CheckSum::sha1(ss).checksum() );
161 result.setTimestamp( lhs.timestamp() < rhs.timestamp() ? rhs.timestamp() : lhs.timestamp() );
165 /******************************************************************
167 ** FUNCTION NAME : operator<<
168 ** FUNCTION TYPE : std::ostream &
170 std::ostream & operator<<( std::ostream & str, const RepoStatus & obj )
172 return str << *obj._pimpl;
175 /////////////////////////////////////////////////////////////////
177 ///////////////////////////////////////////////////////////////////