17#include <zypp/base/Gettext.h>
18#include <zypp/base/Logger.h>
19#include <zypp/base/String.h>
20#include <zypp-core/base/UserRequestException>
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 );
130 std::map<Url, shared_ptr<MediaSetAccess> >::iterator it;
135 it->second->release();
148 std::map<Url, shared_ptr<MediaSetAccess> >::const_iterator it;
150 shared_ptr<MediaSetAccess> media;
168 media->setLabel( repo.
name() );
175 if (
PathInfo(mediafile).isExist() )
177 std::map<shared_ptr<MediaSetAccess>,
RepoInfo>::const_iterator it;
181 if ( it->second.alias() == repo.
alias() )
190 DBG <<
"Verifier for repo '" << repo.
alias() <<
"':" << lverifier << endl;
198 WAR <<
"Invalid verifier for repo '" << repo.
alias() <<
"' in '" << repo.
metadataPath() <<
"': " << lverifier << endl;
203 DBG <<
"No media verifier for repo '" << repo.
alias() <<
"' media.1/media does not exist in '" << repo.
metadataPath() <<
"'" << endl;
208 WAR <<
"'" << repo.
alias() <<
"' metadata path is empty. Can't set verifier. Probably this repository does not come from RepoManager." << endl;
214 std::map<Url, shared_ptr<MediaSetAccess> >
_medias;
223 : _impl( new
Impl( defaultPolicy_r ) )
230 {
_impl->_defaultPolicy = policy_r; }
233 {
return _impl->_defaultPolicy; }
241 MIL << locWithPath << endl;
248 str::form(
_(
"Can't provide file '%s' from repository '%s'"),
250 repo_r.
alias().c_str() ) );
271 assert_dir( destinationDir );
274 if ( geteuid() != 0 && ! pi.
userMayW() )
276 WAR <<
"Destination dir '" << destinationDir <<
"' is not user writable, using tmp space." << endl;
277 destinationDir = getZYpp()->tmpPath() / destinationDir;
278 assert_dir( destinationDir );
280 MIL <<
"Added cache path " << destinationDir << endl;
294 MIL <<
"Providing file of repo '" << repo_r.
alias() <<
"' from " << url << endl;
295 shared_ptr<MediaSetAccess> access =
_impl->mediaAccessForUrl( url, repo_r );
298 fetcher.
start( destinationDir, *access );
307 MIL <<
"provideFile at " << ret << endl;
324 WAR <<
"Trying next url" << endl;
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
Base class for Exception.
void remember(const Exception &old_r)
Store an other Exception as history.
This class allows to retrieve a group of files in a confortable way, providing some smartness that do...
void start(const Pathname &dest_dir, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
start the transfer to a destination directory dest_dir The media has to be provides with setMediaSetA...
void enqueue(const OnMediaLocation &resource, const FileChecker &checker=FileChecker())
Enqueue a object for transferal, they will not be transferred until start() is called.
void addCachePath(const Pathname &cache_dir)
adds a directory to the list of directories where to look for cached files
Policy for provideFile and RepoMediaAccess.
ProvideFilePolicy & fileChecker(FileChecker fileChecker_r)
Add a FileCecker passed down to the Fetcher.
bool progress(int value) const
Evaluate callback.
What is known about a repository.
Pathname metadataPath() const
Path where this repo metadata was read from.
bool baseUrlsEmpty() const
whether repository urls are available
urls_size_type baseUrlsSize() const
number of repository urls
bool keepPackages() const
Whether packages downloaded from this repository will be kept in local cache.
urls_const_iterator baseUrlsEnd() const
iterator that points at end of repository urls
Pathname path() const
Repository path.
urls_const_iterator baseUrlsBegin() const
iterator that points at begin of repository urls
Pathname packagesPath() const
Path where this repo packages are cached.
transform_iterator< repo::RepoVariablesUrlReplacer, url_set::const_iterator > urls_const_iterator
Base for exceptions caused by explicit user request.
Wrapper class for stat/lstat.
bool isExist() const
Return whether valid stat info exists.
const char * c_str() const
String representation.
bool empty() const
Test for an empty path.
Exception for repository handling.
std::string name() const
Repository name.
std::string alias() const
unique identifier for this source.
int unlink(const Pathname &path)
Like 'unlink'.
ManagedFile provideFile(RepoInfo repo_r, const OnMediaLocation &loc_r, const ProvideFilePolicy &policy_r)
Provide a file from a Repository.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Easy-to use interface to the ZYPP dependency resolver.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Wrapper for const correct access via Smart pointer types.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.