RepoStatus RepoManager::cacheStatus( const RepoInfo &info ) const
{
- RepoStatus status;
+
Pathname base = _pimpl->options.repoCachePath + info.alias();
- Pathname solvfile = base.extend(".solv");
Pathname cookiefile = base.extend(".cookie");
- std::ifstream file(cookiefile.c_str());
- if (!file) {
- ZYPP_THROW (Exception( "Can't open " + cookiefile.asString() ) );
- }
-
- std::string buffer;
- while(file && !file.eof()) {
- getline(file, buffer);
- }
-
- std::vector<std::string> words;
- if ( str::split( buffer, std::back_inserter(words) ) != 2 )
- ZYPP_THROW (Exception( "corrupt file " + cookiefile.asString() ) );
-
- status.setTimestamp(Date(str::strtonum<time_t>(words[1])));
- status.setChecksum(words[0]);
- return status;
+ return RepoStatus::fromCookieFile(cookiefile);
}
void RepoManager::setCacheStatus( const string &alias, const RepoStatus &status )
*/
#include <iostream>
#include <sstream>
+#include <vector>
+#include <algorithm>
+#include <fstream>
//#include "zypp/base/Logger.h"
+#include "zypp/base/String.h"
#include "zypp/RepoStatus.h"
#include "zypp/PathInfo.h"
RepoStatus::~RepoStatus()
{}
+ RepoStatus RepoStatus::fromCookieFile( const Pathname &cookiefile )
+ {
+ RepoStatus status;
+
+ std::ifstream file(cookiefile.c_str());
+ if (!file) {
+ ZYPP_THROW (Exception( "Can't open " + cookiefile.asString() ) );
+ }
+
+ std::string buffer;
+ while(file && !file.eof()) {
+ getline(file, buffer);
+ }
+
+ std::vector<std::string> words;
+ if ( str::split( buffer, std::back_inserter(words) ) != 2 )
+ ZYPP_THROW (Exception( "bad cookie file " + cookiefile.asString() ) );
+
+ status.setTimestamp(Date(str::strtonum<time_t>(words[1])));
+ status.setChecksum(words[0]);
+ return status;
+ }
+
RepoStatus::RepoStatus( const Pathname &path )
: _pimpl( new Impl() )
{
public:
/**
+ * reads the status from a file which contains the
+ * checksum and timestamp in each line.
+ *
+ * \throws Exception If the file is not valid or accessible
+ */
+ static RepoStatus fromCookieFile( const Pathname &path );
+
+ /**
* Checksum of the repository.
* Usually the checksum of the index, but any
* checksum that changes when the repository changes