////////////////////////////////////////////////////////////////////////////
+ RepoStatus RepoManager::rawMetadataStatus( const RepoInfo &info )
+ {
+ Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info );
+ RepoType repokind = info.type();
+ switch ( repokind.toEnum() )
+ {
+ case RepoType::NONE_e:
+ // unknown, probe the local metadata
+ repokind = probe(Url(rawpath.asString()));
+ break;
+ default:
+ break;
+ }
+
+ switch ( repokind.toEnum() )
+ {
+ case RepoType::RPMMD_e :
+ {
+ return RepoStatus( rawpath + "/repodata/repomd.xml");
+ }
+ break;
+ case RepoType::YAST2_e :
+ {
+ return RepoStatus( rawpath + "/content");
+ }
+ break;
+ default:
+ ZYPP_THROW(RepoUnknownTypeException());
+ }
+ }
+
+ RepoStatus RepoManager::cacheStatus( const RepoInfo &info )
+ {
+ return RepoStatus();
+ }
+
+
void RepoManager::refreshMetadata( const RepoInfo &info,
+ RepoRefreshPolicy policy,
const ProgressData::ReceiverFnc & progress )
{
assert_alias(info);
assert_urls(info);
+ RepoStatus oldstatus;
+ RepoStatus newstatus;
// try urls one by one
for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin(); it != info.baseUrlsEnd(); ++it )
{
break;
}
+ Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info );
+ oldstatus = rawMetadataStatus(info);
+
switch ( repokind.toEnum() )
{
case RepoType::RPMMD_e :
{
yum::Downloader downloader( url, "/" );
- downloader.download(tmpdir.path());
+
+ RepoStatus newstatus = downloader.status();
+ bool refresh = false;
+ if ( oldstatus.checksum() == newstatus.checksum() )
+ {
+ MIL << "repo has not changed" << endl;
+ if ( policy == RefreshForced )
+ {
+ MIL << "refresh set to forced" << endl;
+ refresh = true;
+ }
+ }
+
+ if ( refresh )
+ downloader.download(tmpdir.path());
+
// no error
}
break;
case RepoType::YAST2_e :
{
susetags::Downloader downloader( url, "/" );
- downloader.download(tmpdir.path());
+
+ RepoStatus newstatus = downloader.status();
+ bool refresh = false;
+ if ( oldstatus.checksum() == newstatus.checksum() )
+ {
+ MIL << "repo has not changed" << endl;
+ if ( policy == RefreshForced )
+ {
+ MIL << "refresh set to forced" << endl;
+ refresh = true;
+ }
+ }
+
+ if ( refresh )
+ downloader.download(tmpdir.path());
// no error
}
break;
// ok we have the metadata, now exchange
// the contents
- Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info);
TmpDir oldmetadata;
filesystem::assert_dir(rawpath);
filesystem::rename( rawpath, oldmetadata.path() );
////////////////////////////////////////////////////////////////////////////
void RepoManager::buildCache( const RepoInfo &info,
+ CacheBuildPolicy policy,
const ProgressData::ReceiverFnc & progress )
{
assert_alias(info);
ZYPP_THROW(RepoUnknownTypeException());
}
+ // update timestamp and checksum
+ //store.updateRepository(id, )
+
MIL << "Commit cache.." << endl;
store.commit();
}
int counter = 1;
while ( PathInfo(_pimpl->options.knownReposPath + filename).isExist() )
{
- filename = Pathname( filename.asString() );
+ filename = Pathname( filename.asString() + "_" + str::numstring(counter));
+ counter++;
}
+ // now we have a filename that does not exists
+
}
////////////////////////////////////////////////////////////////////////////
#include "zypp/RepoInfo.h"
#include "zypp/repo/RepoException.h"
#include "zypp/repo/RepoType.h"
+#include "zypp/RepoStatus.h"
#include "zypp/ProgressData.h"
///////////////////////////////////////////////////////////////////
enum RepoRefreshPolicy
{
- RefreshIfChanged,
+ RefreshIfNeeded,
RefreshForced
};
+ enum CacheBuildPolicy
+ {
+ BuildIfNeeded,
+ BuildForced
+ };
+
enum RepoAddPolicy
{
};
* \throws Exception on unknown error.
*/
void refreshMetadata( const RepoInfo &info,
+ RepoRefreshPolicy policy = RefreshIfNeeded,
const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
/**
* \throws Exception on unknown error.
*/
void buildCache( const RepoInfo &info,
+ CacheBuildPolicy policy = BuildIfNeeded,
const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
/**
void removeRepository( const std::string & alias,
const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
+ RepoStatus rawMetadataStatus( const RepoInfo &info );
+ RepoStatus cacheStatus( const RepoInfo &info );
+
+
public:
private:
#include <iostream>
//#include "zypp/base/Logger.h"
#include "zypp/RepoStatus.h"
-
+#include "zypp/PathInfo.h"
using namespace std;
// METHOD TYPE : Ctor
//
RepoStatus::RepoStatus()
- : _pimpl( Impl::nullimpl() )
+ : _pimpl( new Impl() )
{}
///////////////////////////////////////////////////////////////////
RepoStatus::~RepoStatus()
{}
+ RepoStatus::RepoStatus( const Pathname &path )
+ {
+ _pimpl->checksum = filesystem::sha1sum(path);
+ }
+
RepoStatus & RepoStatus::setChecksum( const string &checksum )
{
_pimpl->checksum = checksum;
public:
/** Default ctor */
RepoStatus();
+
+ /**
+ * \short Status from a single file
+ * As most repository state is represented
+ * by the status of the index file, you can
+ * construct the status from a file.
+ */
+ RepoStatus( const Pathname &file );
+
/** Dtor */
~RepoStatus();
}
void CacheStore::updateRepository( const RecordId &id,
- const string &checksum,
- const Date ×tamp )
+ const string &checksum,
+ const Date ×tamp )
{
_pimpl->update_repository_cmd->bind(":repository_id", id);
_pimpl->update_repository_cmd->bind(":checksum", checksum);
{
sqlite3_reader reader = cmd.executereader();
RepoStatus status;
- while ( reader.read() )
+ if ( reader.read() )
{
status.setChecksum( reader.getstring(2) );
status.setTimestamp( reader.getstring(3) );
{
return make_map_key_end( _dict );
}
+
+ void IniDict::insertEntry( const std::string §ion,
+ const std::string &key,
+ const std::string &value )
+ {
+ consume( section, key, value );
+ }
+ void IniDict::deleteSection( const std::string §ion )
+ {
+ _dict.erase(section);
+ }
+
/******************************************************************
**
** FUNCTION NAME : operator<<
*/
std::ostream & operator<<( std::ostream & str, const IniDict & obj )
{
+ for ( IniDict::section_const_iterator si = obj.sectionsBegin();
+ si != obj.sectionsEnd();
+ ++si )
+ {
+ str << "[" << *si << "]" << endl;
+ for ( IniDict::entry_const_iterator ei = obj.entriesBegin(*si);
+ ei != obj.entriesEnd(*si);
+ ++ei )
+ {
+ str << ei->first << " = " << ei->second << endl;
+ }
+ str << endl;
+ }
return str;
}
* Creates a dictionary from a InputStream
* containing a ini structured file
*/
- IniDict( const InputStream &is, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
+ IniDict( const InputStream &is,
+ const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
/** Dtor */
~IniDict();
+ /**
+ * \short add an entry
+ * \param section
+ * \param key
+ * \param value
+ */
+ void insertEntry( const std::string §ion,
+ const std::string &key,
+ const std::string &value );
+
+ /**
+ * \short add an entry
+ * \param section
+ * \param key
+ * \param value
+ */
+ void deleteSection( const std::string §ion );
+
public:
/** Called when a section is found. */
virtual void consume( const std::string §ion );
/** Called when a key value is found. */
- virtual void consume( const std::string §ion, const std::string &key, const std::string &value );
+ virtual void consume( const std::string §ion,
+ const std::string &key,
+ const std::string &value );
private:
SectionSet _dict;
-
/**
* empty map used to simulate
* iteration in non existant
else if ( it->first == "type" )
info.setType(repo::RepoType(it->second));
}
-
+ info.setFilepath(file);
// add it to the list.
callback(info);
//if (!progress.tick())
}
+RepoStatus Downloader::status()
+{
+ MediaSetAccess media(_url, _path);
+ Pathname content = media.provideFile("/content");
+ return RepoStatus(content);
+}
+
void Downloader::download( const Pathname &dest_dir,
const ProgressData::ReceiverFnc & progress )
{
#include "zypp/Url.h"
#include "zypp/Pathname.h"
#include "zypp/ProgressData.h"
+#include "zypp/RepoStatus.h"
namespace zypp
{
Downloader( const Url &url, const Pathname &path );
void download( const Pathname &dest_dir,
const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
+ /**
+ * \short Status of the remote repository
+ */
+ RepoStatus status();
private:
Url _url;
Pathname _path;
{
}
+RepoStatus Downloader::status()
+{
+ Pathname repomd = _media.provideFile("/repodata/repomd.xml");
+ return RepoStatus(repomd);
+}
+
bool Downloader::patches_Callback( const OnMediaLocation &loc, const string &id )
{
MIL << id << " : " << loc << endl;
#include "zypp/parser/xml/Reader.h"
#include "zypp/repo/yum/ResourceType.h"
#include "zypp/ProgressData.h"
+#include "zypp/RepoStatus.h"
namespace zypp
{
void download( const Pathname &dest_dir,
const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() );
+ /**
+ * \short Status of the remote repository
+ */
+ RepoStatus status();
+
protected:
bool repomd_Callback( const OnMediaLocation &loc, const ResourceType &dtype );
bool patches_Callback( const OnMediaLocation &loc, const std::string &id );