RepoStatus.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 #include <sstream>
00014 //#include "zypp/base/Logger.h"
00015 #include "zypp/RepoStatus.h"
00016 #include "zypp/PathInfo.h"
00017 
00018 using namespace std;
00019 
00021 namespace zypp
00022 { 
00023 
00025   //
00026   //    CLASS NAME : RepoStatus::Impl
00027   //
00029   struct RepoStatus::Impl
00030   {
00031 
00032   public:
00033     
00034     string checksum;
00035     Date timestamp;
00036     
00038     static shared_ptr<Impl> nullimpl()
00039     {
00040       static shared_ptr<Impl> _nullimpl( new Impl );
00041       return _nullimpl;
00042     }
00043 
00044   private:
00045     friend Impl * rwcowClone<Impl>( const Impl * rhs );
00047     Impl * clone() const
00048     { return new Impl( *this ); }
00049   };
00051 
00053   inline std::ostream & operator<<( std::ostream & str, const RepoStatus::Impl & obj )
00054   {
00055     return str << "RepoStatus::Impl";
00056   }
00057 
00059   //
00060   //    CLASS NAME : RepoStatus
00061   //
00063 
00065   //
00066   //    METHOD NAME : RepoStatus::RepoStatus
00067   //    METHOD TYPE : Ctor
00068   //
00069   RepoStatus::RepoStatus()
00070     : _pimpl( new Impl() )
00071   {}
00072 
00074   //
00075   //    METHOD NAME : RepoStatus::~RepoStatus
00076   //    METHOD TYPE : Dtor
00077   //
00078   RepoStatus::~RepoStatus()
00079   {}
00080 
00081   RepoStatus::RepoStatus( const Pathname &path )
00082     : _pimpl( new Impl() )
00083   {
00084       PathInfo info(path);
00085       if ( info.isExist() )
00086       {
00087         _pimpl->checksum = filesystem::sha1sum(path);
00088         _pimpl->timestamp = Date(info.mtime());
00089       }
00090   }
00091   
00092   bool RepoStatus::empty() const
00093   {
00094     return _pimpl->checksum.empty();
00095   }
00096 
00097   RepoStatus & RepoStatus::setChecksum( const string &checksum )
00098   {
00099     _pimpl->checksum = checksum;
00100     return *this;
00101   }
00102 
00103   RepoStatus & RepoStatus::setTimestamp( const Date &timestamp )
00104   {
00105     _pimpl->timestamp = timestamp;
00106     return *this;
00107   }
00108   
00109   string RepoStatus::checksum() const
00110   { return _pimpl->checksum; }
00111 
00112   Date RepoStatus::timestamp() const
00113   { return _pimpl->timestamp; }
00114   
00115   RepoStatus operator&&( const RepoStatus &lhs, const RepoStatus &rhs )
00116   {
00117     RepoStatus result;
00118     string combinedcs = (lhs.checksum() + rhs.checksum());
00119     stringstream ss(combinedcs);
00120     CheckSum newcs(CheckSum::sha1(ss));
00121     result.setChecksum(newcs.checksum());
00122     result.setTimestamp(lhs.timestamp());
00123     if ( rhs.timestamp() > lhs.timestamp() )
00124       result.setTimestamp(rhs.timestamp());
00125     return result;
00126   }
00127 
00128   /******************************************************************
00129   **
00130   **    FUNCTION NAME : operator<<
00131   **    FUNCTION TYPE : std::ostream &
00132   */
00133   std::ostream & operator<<( std::ostream & str, const RepoStatus & obj )
00134   {
00135     return str << *obj._pimpl;
00136   }
00137 
00139 } // namespace zypp

Generated on Tue Sep 25 19:23:06 2007 for libzypp by  doxygen 1.5.3