59 struct DownloadFileReportHack :
public callback::ReceiveReport<media::DownloadProgressReport>
61 typedef callback::ReceiveReport<ReportType> BaseType;
62 typedef function<bool(int)> RedirectType;
64 DownloadFileReportHack( RedirectType redirect_r )
65 :
_oldRec( Distributor::instance().getReceiver() )
68 ~DownloadFileReportHack()
69 {
if (
_oldRec ) Distributor::instance().setReceiver( *
_oldRec );
else Distributor::instance().noReceiver(); }
71 virtual void start(
const Url & file, Pathname localfile )
74 _oldRec->start( file, localfile );
76 BaseType::start( file, localfile );
79 virtual bool progress(
int value,
const Url & file,
double dbps_avg = -1,
double dbps_current = -1 )
83 ret &=
_oldRec->progress( value, file, dbps_avg, dbps_current );
89 virtual Action problem(
const Url & file, Error
error,
const std::string & description )
92 return _oldRec->problem( file, error, description );
93 return BaseType::problem( file, error, description );
95 virtual void finish(
const Url & file, Error error,
const std::string & reason )
98 _oldRec->finish( file, error, reason );
100 BaseType::finish( file, error, reason );
117 return access.
provideFile(repo_r, loc_r, policy_r );
125 : _defaultPolicy( defaultPolicy_r )
130 std::map<Url, shared_ptr<MediaSetAccess> >::iterator it;
131 for ( it = _medias.begin();
135 it->second->release();
148 std::map<Url, shared_ptr<MediaSetAccess> >::const_iterator it;
149 it = _medias.find(url);
150 shared_ptr<MediaSetAccess> media;
151 if ( it != _medias.end() )
158 _medias[
url] = media;
160 setVerifierForRepo( repo, media );
168 media->setLabel( repo.
name() );
172 Pathname mediafile = repo.
metadataPath() +
"/media.1/media";
175 if ( PathInfo(mediafile).isExist() )
177 std::map<shared_ptr<MediaSetAccess>,
RepoInfo>::const_iterator it;
178 it = _verifier.find(media);
179 if ( it != _verifier.end() )
181 if ( it->second.alias() == repo.
alias() )
188 std::ifstream
str(mediafile.asString().c_str());
198 unsigned media_nr = str::strtonum<unsigned>(buffer);
199 MIL <<
"Repository '" << repo.
alias() <<
"' has " << media_nr <<
" medias"<< endl;
201 for (
unsigned i=1; i <= media_nr; ++i )
205 media->setVerifier( i, verifier);
207 _verifier[media] = repo;
216 WAR <<
"No media verifier for repo '" << repo.
alias() <<
"' media/media.1 does not exist in '" << repo.
metadataPath() <<
"'" << endl;
221 WAR <<
"'" << repo.
alias() <<
"' metadata path is empty. Can't set verifier. Probably this repository does not come from RepoManager." << endl;
227 std::map<Url, shared_ptr<MediaSetAccess> >
_medias;
236 : _impl( new
Impl( defaultPolicy_r ) )
252 MIL << loc_r << endl;
259 str::form(
_(
"Can't provide file '%s' from repository '%s'"),
261 repo_r.
alias().c_str() ) );
278 PathInfo pi( destinationDir );
279 if ( ! pi.isExist() )
285 if ( geteuid() != 0 && ! pi.userMayW() )
287 WAR <<
"Destination dir '" << destinationDir <<
"' is not user writable, using tmp space." << endl;
288 destinationDir = getZYpp()->tmpPath() / destinationDir;
291 MIL <<
"Added cache path " << destinationDir << endl;
305 MIL <<
"Providing file of repo '" << repo_r.
alias()
306 <<
"' from " << url << endl;
312 fetcher.
start( destinationDir, *access );
326 WAR <<
"No checksum in metadata " << loc_r << endl;
330 std::ifstream input( ret->asString().c_str() );
334 if ( loc_r.
checksum() != retChecksum )
337 std::ostringstream err;
338 err <<
"File " << ret <<
" fails integrity check. Expected: [" << loc_r.
checksum() <<
"] Got: [";
339 if ( retChecksum.empty() )
340 err <<
"Failed to compute checksum";
345 WAR << err.str() << endl;
350 WAR <<
"NO failOnChecksumError: " << err.str() << endl;
354 MIL <<
"provideFile at " << ret << endl;
357 catch (
const SkipRequestException &e )
362 catch (
const AbortRequestException &e )
373 WAR <<
"Trying next url" << endl;
std::string name() const
Repository name.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
std::string alias() const
unique identifier for this source.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
urls_const_iterator baseUrlsBegin() const
iterator that points at begin of repository urls
Pathname metadataPath() const
Path where this repo metadata was read from.
String related utilities and Regular expression matching.
What is known about a repository.
void addCachePath(const Pathname &cache_dir)
adds a directory to the list of directories where to look for cached files
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
urls_const_iterator baseUrlsEnd() const
iterator that points at end of repository urls
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Pathname packagesPath() const
Path where this repo packages are cached.
void remember(const Exception &old_r)
Store an other Exception as history.
transform_iterator< repo::RepoVariablesUrlReplacer, url_set::const_iterator > urls_const_iterator
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
std::string getline(std::istream &str)
Read one line from stream.
bool keepPackages() const
Whether packages downloaded from this repository will be kept in local cache.
ManagedFile provideFile(RepoInfo repo_r, const OnMediaLocation &loc_r, const ProvideFilePolicy &policy_r)
Provide a file from a Repository.
int unlink(const Pathname &path)
Like 'unlink'.
bool progress(int value) const
Evaluate callback.
void start(const Pathname &dest_dir, MediaSetAccess &media, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
start the transfer to a destination directory dest_dir You have to provde a media set access media to...
bool baseUrlsEmpty() const
whether repository urls are available
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Base class for Exception.
Exception for repository handling.
Wrapper for const correct access via Smart pointer types.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
std::string getScheme() const
Returns the scheme name of the URL.
urls_size_type baseUrlsSize() const
number of repository urls
void enqueue(const OnMediaLocation &resource, const FileChecker &checker=FileChecker())
Enqueue a object for transferal, they will not be transferred until start() is called.
bool failOnChecksumError() const
Evaluate callback.
Easy-to use interface to the ZYPP dependency resolver.
This class allows to retrieve a group of files in a confortable way, providing some smartness that do...