*/
ManagedFile providePackage() const;
+ /** Provide the package if it is cached. */
+ ManagedFile providePackageFromCache() const
+ {
+ ManagedFile ret( doProvidePackageFromCache() );
+ if ( ! ( ret->empty() || _package->repoInfo().keepPackages() ) )
+ ret.setDispose( filesystem::unlink );
+ return ret;
+ }
+
+ /** Whether the package is cached. */
+ bool isCached() const
+ { return ! doProvidePackageFromCache()->empty(); }
+
protected:
typedef PackageProvider::Impl Base;
typedef callback::SendReport<repo::DownloadResolvableReport> Report;
/** Lookup the final rpm in cache.
*
- * A non empty ManagedFile will be returned to the caller. File disposal
- * depending on the repos keepPackages setting are handled in \ref providePackage.
+ * A non empty ManagedFile will be returned to the caller.
+ *
+ * \note File disposal depending on the repos keepPackages setting
+ * are not set here, but in \ref providePackage or \ref providePackageFromCache.
*
* \note The provoided default implementation returns an empty ManagedFile
* (cache miss).
*/
- virtual ManagedFile providePackageFromCache() const = 0;
+ virtual ManagedFile doProvidePackageFromCache() const = 0;
/** Actually provide the final rpm.
* Report start/problem/finish and retry loop are hadled by \ref providePackage.
///////////////////////////////////////////////////////////////////
/** Default implementation (cache miss). */
- ManagedFile PackageProvider::Impl::providePackageFromCache() const
+ ManagedFile PackageProvider::Impl::doProvidePackageFromCache() const
{ return ManagedFile(); }
/** Default implementation (provide full package) */
ManagedFile PackageProvider::Impl::providePackage() const
{
- Url url;
- RepoInfo info = _package->repoInfo();
- // FIXME we only support the first url for now.
- if ( info.baseUrlsEmpty() )
- ZYPP_THROW(Exception("No url in repository."));
- else
- url = * info.baseUrlsBegin();
-
// check for cache hit:
ManagedFile ret( providePackageFromCache() );
- if ( ! ret.value().empty() )
+ if ( ! ret->empty() )
{
- if ( ! info.keepPackages() )
- {
- ret.setDispose( filesystem::unlink );
- }
MIL << "provided Package from cache " << _package << " at " << ret << endl;
return ret; // <-- cache hit
}
// HERE: cache misss, do download:
+ Url url;
+ RepoInfo info = _package->repoInfo();
+ // FIXME we only support the first url for now.
+ if ( info.baseUrlsEmpty() )
+ ZYPP_THROW(Exception("No url in repository."));
+ else
+ url = * info.baseUrlsBegin();
+
MIL << "provide Package " << _package << endl;
ScopedGuard guardReport( newReport() );
do {
{}
protected:
- virtual ManagedFile providePackageFromCache() const;
+ virtual ManagedFile doProvidePackageFromCache() const;
virtual ManagedFile doProvidePackage() const;
};
///////////////////////////////////////////////////////////////////
- ManagedFile RpmPackageProvider::providePackageFromCache() const
+ ManagedFile RpmPackageProvider::doProvidePackageFromCache() const
{
- RepoInfo info = _package->repoInfo();
- OnMediaLocation loc( _package->location() );
- PathInfo cachepath( info.packagesPath() / loc.filename() );
-
- if ( cachepath.isFile() && ! loc.checksum().empty() ) // accept cache hit with matching checksum only!
- // Tempting to do a quick check for matching .rpm-filesize before computing checksum,
- // but real life shows that loc.downloadSize() and the .rpm-filesize frequently do not
- // match, even if loc.checksum() and the .rpm-files checksum do. Blame the metadata generator(s).
- {
- CheckSum cachechecksum( loc.checksum().type(), filesystem::checksum( cachepath.path(), loc.checksum().type() ) );
- if ( cachechecksum == loc.checksum() )
- {
- return ManagedFile( cachepath.path() ); // <-- cache hit
- }
- }
- return ManagedFile(); // <-- cache miss
+ return ManagedFile( _package->cachedLocation() );
}
ManagedFile RpmPackageProvider::doProvidePackage() const
return ManagedFile( destination, filesystem::unlink );
}
-
+#if 0
///////////////////////////////////////////////////////////////////
/// \class PluginPackageProvider
/// \brief Plugin PackageProvider implementation.
{}
protected:
- virtual ManagedFile providePackageFromCache() const
+ virtual ManagedFile doProvidePackageFromCache() const
{
- return Base::providePackageFromCache();
+ return Base::doProvidePackageFromCache();
}
virtual ManagedFile doProvidePackage() const
}
};
///////////////////////////////////////////////////////////////////
-
+#endif
///////////////////////////////////////////////////////////////////
// class PackageProvider
ManagedFile PackageProvider::providePackage() const
{ return _pimpl->providePackage(); }
+ ManagedFile PackageProvider::providePackageFromCache() const
+ { return _pimpl->providePackageFromCache(); }
+
+ bool PackageProvider::isCached() const
+ { return _pimpl->isCached(); }
} // namespace repo
///////////////////////////////////////////////////////////////////