- move the cookie code to RepoStatus to reuse it in target
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 1 Feb 2008 23:19:51 +0000 (23:19 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 1 Feb 2008 23:19:51 +0000 (23:19 +0000)
zypp/RepoManager.cc
zypp/RepoStatus.cc
zypp/RepoStatus.h

index b1f7412..eb843ae 100644 (file)
@@ -873,28 +873,11 @@ namespace zypp
 
   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 )
index 89f8e70..1f5af4b 100644 (file)
 */
 #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"
 
@@ -78,6 +82,29 @@ namespace zypp
   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() )
   {
index fa41dd7..211f17f 100644 (file)
@@ -41,6 +41,14 @@ namespace zypp
   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