21#include <zypp-core/base/UserRequestException>
60 struct DownloadFileReportHack :
public callback::ReceiveReport<media::DownloadProgressReport>
62 using BaseType = callback::ReceiveReport<ReportType>;
63 using RedirectType = function<bool (
int)>;
65 DownloadFileReportHack(RedirectType &&redirect_r)
66 : _oldRec(Distributor::instance().getReceiver()),
67 _redirect(std::move(redirect_r)) {
71 DownloadFileReportHack(
const DownloadFileReportHack &) =
delete;
72 DownloadFileReportHack(DownloadFileReportHack &&) =
delete;
73 DownloadFileReportHack &
operator=(
const DownloadFileReportHack &) =
delete;
74 DownloadFileReportHack &
operator=(DownloadFileReportHack &&) =
delete;
76 ~DownloadFileReportHack()
override
77 {
if ( _oldRec ) Distributor::instance().setReceiver( *_oldRec );
else Distributor::instance().noReceiver(); }
79 void start(
const Url & file, Pathname localfile )
override
82 _oldRec->start( file, localfile );
84 BaseType::start( file, localfile );
87 bool progress(
int value,
const Url & file,
double dbps_avg = -1,
double dbps_current = -1 )
override
91 ret &= _oldRec->progress( value, file, dbps_avg, dbps_current );
93 ret &= _redirect( value );
97 Action problem(
const Url & file, Error error,
const std::string & description )
override
100 return _oldRec->problem( file, error, description );
101 return BaseType::problem( file, error, description );
103 void finish(
const Url & file, Error error,
const std::string & reason )
override
106 _oldRec->finish( file, error, reason );
108 BaseType::finish( file, error, reason );
113 RedirectType _redirect;
125 return access.
provideFile(std::move(repo_r), loc_r, policy_r );
142 std::map<Url, shared_ptr<MediaSetAccess> >::iterator it;
147 it->second->release();
160 std::map<Url, shared_ptr<MediaSetAccess> >::const_iterator it;
184 Pathname mediafile =
repo.metadataPath() +
"/media.1/media";
185 if ( !
repo.metadataPath().empty() )
187 if (
PathInfo(mediafile).isExist() )
189 std::map<shared_ptr<MediaSetAccess>,
RepoInfo>::const_iterator it;
193 if ( it->second.alias() ==
repo.alias() )
202 DBG <<
"Verifier for repo '" <<
repo.alias() <<
"':" << lverifier << endl;
205 media->setVerifier( i, verifier);
210 WAR <<
"Invalid verifier for repo '" <<
repo.alias() <<
"' in '" <<
repo.metadataPath() <<
"': " << lverifier << endl;
215 DBG <<
"No media verifier for repo '" <<
repo.alias() <<
"' media.1/media does not exist in '" <<
repo.metadataPath() <<
"'" << endl;
220 WAR <<
"'" <<
repo.alias() <<
"' metadata path is empty. Can't set verifier. Probably this repository does not come from RepoManager." << endl;
226 std::map<Url, shared_ptr<MediaSetAccess> >
_medias;
242 {
_impl->_defaultPolicy = policy_r; }
245 {
return _impl->_defaultPolicy; }
253 MIL << locWithPath << endl;
260 str::form(
_(
"Can't provide file '%s' from repository '%s'"),
262 repo_r.
alias().c_str() ) );
285 assert_dir( destinationDir );
288 if ( geteuid() != 0 && ! pi.
userMayW() )
290 WAR <<
"Destination dir '" << destinationDir <<
"' is not user writable, using tmp space." << endl;
291 destinationDir =
getZYpp()->tmpPath() / destinationDir;
292 assert_dir( destinationDir );
294 MIL <<
"Added cache path " << destinationDir << endl;
308 MIL <<
"Providing file of repo '" << repo_r.
alias() <<
"' from " <<
url << endl;
312 fetcher.
start( destinationDir, *access );
321 MIL <<
"provideFile at " << ret << endl;
338 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.
bool baseUrlsEmpty() const
whether repository urls are available
Pathname predownloadPath() const
Path where this repo packages are predownloaded.
transform_iterator< repo::RepoVariablesUrlReplacer, url_set::const_iterator > urls_const_iterator
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.
Base for exceptions caused by explicit user request.
ZYpp::Ptr getZYpp()
Convenience to get the Pointer to the ZYpp instance.
Wrapper class for stat/lstat.
bool isExist() const
Return whether valid stat info exists.
const char * c_str() const
String representation.
Exception for repository handling.
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.
SolvableSpec & operator=(const SolvableSpec &)=default
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.
#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.