{
// does the current file exists in the current cache?
Pathname cached_file = *it_cache + (*it_res)->location.filename();
+
+ MIL << "Trying cached file: " << cached_file << endl;
+
if ( PathInfo( cached_file ).isExist() )
{
+ MIL << "File exist, testing checksum " << (*it_res)->location.checksum() << endl;
+
// check the checksum
if ( is_checksum( cached_file, (*it_res)->location.checksum() ) && (! (*it_res)->location.checksum().empty() ) )
{
// replicate the complete path in the target directory
Pathname dest_full_path = dest_dir + (*it_res)->location.filename();
- if ( assert_dir( dest_full_path.dirname() ) != 0 )
- ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString()));
+
+ if( dest_full_path != cached_file )
+ {
+ if ( assert_dir( dest_full_path.dirname() ) != 0 )
+ ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString()));
- if ( filesystem::copy(cached_file, dest_full_path ) != 0 )
- { //copy_file2dir
- //ZYPP_THROW(SourceIOException("Can't copy " + cached_file.asString() + " to " + destination.asString()));
- ERR << "Can't copy " << cached_file + " to " + dest_dir << endl;
- // try next cache
- continue;
- }
+ if ( filesystem::copy(cached_file, dest_full_path ) != 0 )
+ { //copy_file2dir
+ //ZYPP_THROW(SourceIOException("Can't copy " + cached_file.asString() + " to " + destination.asString()));
+ ERR << "Can't copy " << cached_file + " to " + dest_dir << endl;
+ // try next cache
+ continue;
+ }
+ }
got_from_cache = true;
break;
if ( ! got_from_cache )
{
+ MIL << "Not found in cache, downloading" << endl;
+
// try to get the file from the net
try
{
: enabled (false),
autorefresh(false),
gpgcheck(true),
+ keeppackages(false),
type(repo::RepoType::NONE_e)
{}
bool enabled;
bool autorefresh;
bool gpgcheck;
+ bool keeppackages;
Url gpgkey_url;
repo::RepoType type;
Url mirrorlist_url;
std::string name;
Pathname filepath;
Pathname metadatapath;
+ Pathname packagespath;
public:
private:
return *this;
}
+ RepoInfo & RepoInfo::setPackagesPath( const Pathname &path )
+ {
+ _pimpl->packagespath = path;
+ return *this;
+ }
+
+ RepoInfo & RepoInfo::setKeepPackages( bool keep )
+ {
+ _pimpl->keeppackages = keep;
+ return *this;
+ }
+
bool RepoInfo::enabled() const
{ return _pimpl->enabled; }
Pathname RepoInfo::metadataPath() const
{ return _pimpl->metadatapath; }
+ Pathname RepoInfo::packagesPath() const
+ { return _pimpl->packagespath; }
+
repo::RepoType RepoInfo::type() const
{ return _pimpl->type; }
bool RepoInfo::baseUrlsEmpty() const
{ return _pimpl->baseUrls.empty(); }
+ bool RepoInfo::keepPackages() const
+ { return _pimpl->keeppackages; }
+
std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
{
str << "--------------------------------------" << std::endl;
str << "- autorefresh : " << autorefresh() << std::endl;
str << "- gpgcheck : " << gpgCheck() << std::endl;
str << "- gpgkey : " << gpgKeyUrl() << std::endl;
+ str << "- keeppackages : " << keepPackages() << std::endl;
return str;
}
str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
if ( ! (gpgKeyUrl().asString().empty()) )
str << "gpgkey=" <<gpgKeyUrl() << endl;
+
+ str << "keeppackages=" << keepPackages() << endl;
return str;
}
*/
Pathname metadataPath() const;
+ /**
+ * \short Path where this repo packages are cached
+ */
+ Pathname packagesPath() const;
+
/**
* \short Whether to check or not this repository with gpg
*
*/
Url gpgKeyUrl() const;
+ /**
+ * \short Whether to keep the packages downloaded from this repository will be kept in local cache
+ */
+ bool keepPackages() const;
+
/**
* Add a base url. \see baseUrls
* \param url The base url for the repository.
*/
RepoInfo & setMetadataPath( const Pathname &path );
+ /**
+ * \short set the path where the local packages are stored
+ *
+ * \param path directory path
+ */
+ RepoInfo & setPackagesPath( const Pathname &path );
+
/**
* \short Whether to check or not this repository with gpg
*
*
*/
RepoInfo & setGpgKeyUrl( const Url &gpgkey );
+
+ /**
+ * \short Set if the packaqes downloaded from this repository will be kept in local cache
+ *
+ * If the setting is true, all downloaded packages from this repository will be
+ * copied to the local raw cache.
+ *
+ * \param keep true (keep the downloaded packages) or false (delete them after installation)
+ *
+ */
+ RepoInfo & setKeepPackages( bool keep );
/**
* Write a human-readable representation of this RepoInfo object
{
repoCachePath = ZConfig::instance().repoCachePath();
repoRawCachePath = ZConfig::instance().repoMetadataPath();
+ repoPackagesCachePath = ZConfig::instance().repoPackagesPath();
knownReposPath = ZConfig::instance().knownReposPath();
}
return opt.repoRawCachePath + info.alias();
}
+ /**
+ * \short Calculates the packages cache path for a repository
+ */
+ static Pathname packagescache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
+ {
+ assert_alias(info);
+ return opt.repoPackagesCachePath + info.alias();
+ }
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : RepoManager::Impl
// set the metadata path for the repo
Pathname metadata_path = rawcache_path_for_repoinfo(_pimpl->options, (*it));
(*it).setMetadataPath(metadata_path);
+
+ // set the downloaded packages path for the repo
+ Pathname packages_path = packagescache_path_for_repoinfo(_pimpl->options, (*it));
+ (*it).setPackagesPath(packages_path);
}
return repos;
}
// ok we have the metadata, now exchange
// the contents
- TmpDir oldmetadata( TmpDir::makeSibling( rawpath ) );
- filesystem::rename( rawpath, oldmetadata.path() );
+
+ // first, clean up the old rawcache metadata
+ // #FIXME
+ // now, move the new metadata in
+ // #FIXME
+
+ //TmpDir oldmetadata( TmpDir::makeSibling( rawpath ) );
+ //filesystem::rename( rawpath, oldmetadata.path() );
// move the just downloaded there
- filesystem::rename( tmpdir.path(), rawpath );
+ //filesystem::rename( tmpdir.path(), rawpath );
+
// we are done.
return;
}
Pathname repoCachePath;
Pathname repoRawCachePath;
+ Pathname repoPackagesCachePath;
Pathname knownReposPath;
};
{
cfg_vendor_path = Pathname(value);
}
+ else if ( entry == "packagesdir" )
+ {
+ cfg_packages_path = Pathname(value);
+ }
}
}
}
Locale cfg_textLocale;
Pathname cfg_metadata_path;
+ Pathname cfg_packages_path;
Pathname cfg_cache_path;
Pathname cfg_known_repos_path;
Pathname cfg_vendor_path;
? Pathname("/var/cache/zypp/raw") : _pimpl->cfg_metadata_path );
}
+ Pathname ZConfig::repoPackagesPath() const
+ {
+ return ( _pimpl->cfg_packages_path.empty()
+ ? Pathname("/var/cache/zypp/packages") : _pimpl->cfg_packages_path );
+ }
+
Pathname ZConfig::repoCachePath() const
{
return ( _pimpl->cfg_cache_path.empty()
*/
Pathname repoMetadataPath() const;
+ /**
+ * Path where the repo packages are downloaded and kept.
+ */
+ Pathname repoPackagesPath() const;
+
/**
* Path where the processed cache is kept
* (this is where zypp.db is located.
info.setGpgKeyUrl( Url(it->second) );
else if ( it->first == "gpgcheck" )
info.setGpgCheck( it->second == "1" );
+ else if ( it->first == "keeppackages" )
+ info.setKeepPackages( it->second == "1" );
else
ERR << "Unknown attribute " << it->second << " ignored" << endl;
}
#include "zypp/repo/SUSEMediaVerifier.h"
#include "zypp/repo/RepoException.h"
#include "zypp/FileChecker.h"
+#include "zypp/Fetcher.h"
using std::endl;
using std::set;
repo_excpt.remember(RepoException(_("No url in repository.")));
ZYPP_THROW(repo_excpt);
}
+
+ Fetcher fetcher;
+ fetcher.addCachePath( info.packagesPath() );
+ MIL << "Added cache path " << info.packagesPath() << endl;
+
for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin();
it != info.baseUrlsEnd();
/* incremented in the loop */ )
<< "' from " << url << endl;
shared_ptr<MediaSetAccess> access = _impl->mediaAccessForUrl(url);
_impl->setVerifierForRepo(repo_r, access);
+
+ fetcher.enqueue( loc_r );
+
+ // FIXME: works for packages only
+ fetcher.start( info.packagesPath(), *access );
- ManagedFile ret( access->provideFile(loc_r) );
+ // reached if no exception has been thrown, so this is the correct file
+ ManagedFile ret( info.packagesPath() + loc_r.filename() );
std::string scheme( url.getScheme() );
- if ( scheme == "http" || scheme == "https" || scheme == "ftp" )
+ if ( !info.keepPackages() )
{
ret.setDispose( filesystem::unlink );
}