22#include <zypp-core/base/UserRequestException>
61 struct DownloadFileReportHack :
public callback::ReceiveReport<media::DownloadProgressReport>
63 using BaseType = callback::ReceiveReport<ReportType>;
64 using RedirectType = function<bool (
int)>;
66 DownloadFileReportHack(RedirectType &&redirect_r)
67 : _oldRec(Distributor::instance().getReceiver()),
68 _redirect(std::move(redirect_r)) {
72 DownloadFileReportHack(
const DownloadFileReportHack &) =
delete;
73 DownloadFileReportHack(DownloadFileReportHack &&) =
delete;
74 DownloadFileReportHack &
operator=(
const DownloadFileReportHack &) =
delete;
75 DownloadFileReportHack &
operator=(DownloadFileReportHack &&) =
delete;
77 ~DownloadFileReportHack()
override
78 {
if ( _oldRec ) Distributor::instance().setReceiver( *_oldRec );
else Distributor::instance().noReceiver(); }
80 void start(
const Url & file, Pathname localfile )
override
83 _oldRec->start( file, localfile );
85 BaseType::start( file, localfile );
88 bool progress(
int value,
const Url & file,
double dbps_avg = -1,
double dbps_current = -1 )
override
92 ret &= _oldRec->progress( value, file, dbps_avg, dbps_current );
94 ret &= _redirect( value );
98 Action problem(
const Url & file, Error error,
const std::string & description )
override
101 return _oldRec->problem( file, error, description );
102 return BaseType::problem( file, error, description );
104 void finish(
const Url & file, Error error,
const std::string & reason )
override
107 _oldRec->finish( file, error, reason );
109 BaseType::finish( file, error, reason );
114 RedirectType _redirect;
126 return access.
provideFile(std::move(repo_r), loc_r, policy_r );
143 std::map<Url, shared_ptr<MediaSetAccess> >::iterator it;
148 it->second->release();
164 std::map<Url, shared_ptr<MediaSetAccess> >::const_iterator it;
188 Pathname mediafile =
repo.metadataPath() +
"/media.1/media";
189 if ( !
repo.metadataPath().empty() )
191 if (
PathInfo(mediafile).isExist() )
193 std::map<shared_ptr<MediaSetAccess>,
RepoInfo>::const_iterator it;
197 if ( it->second.alias() ==
repo.alias() )
206 DBG <<
"Verifier for repo '" <<
repo.alias() <<
"':" << lverifier << endl;
209 media->setVerifier( i, verifier);
214 WAR <<
"Invalid verifier for repo '" <<
repo.alias() <<
"' in '" <<
repo.metadataPath() <<
"': " << lverifier << endl;
219 DBG <<
"No media verifier for repo '" <<
repo.alias() <<
"' media.1/media does not exist in '" <<
repo.metadataPath() <<
"'" << endl;
224 WAR <<
"'" <<
repo.alias() <<
"' metadata path is empty. Can't set verifier. Probably this repository does not come from RepoManager." << endl;
230 std::map<Url, shared_ptr<MediaSetAccess> >
_medias;
246 {
_impl->_defaultPolicy = policy_r; }
249 {
return _impl->_defaultPolicy; }
257 MIL << locWithPath << endl;
264 str::form(
_(
"Can't provide file '%s' from repository '%s'"),
266 repo_r.
alias().c_str() ) );
270 if ( repoOrigins.empty() ) {
290 assert_dir( destinationDir );
293 if ( geteuid() != 0 && ! pi.
userMayW() )
295 WAR <<
"Destination dir '" << destinationDir <<
"' is not user writable, using tmp space." << endl;
296 destinationDir =
getZYpp()->tmpPath() / destinationDir;
297 assert_dir( destinationDir );
299 MIL <<
"Added cache path " << destinationDir << endl;
304 for (
const auto &origin : repoOrigins )
307 if ( !origin.isValid() ) {
308 MIL <<
"Skipping empty Url group" << std::endl;
314 MIL <<
"Providing file of repo '" << repo_r.
alias() <<
"' from: ";
315 std::for_each( origin.begin (), origin.end(), [&](
const OriginEndpoint &u ){
325 fetcher.
start( destinationDir, *access );
339 MIL <<
"provideFile at " << ret << endl;
356 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
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
const OriginEndpoint & authority() const
Represents a single, configurable network endpoint, combining a URL with specific access settings.
const zypp::Url & url() const
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 predownloadPath() const
Path where this repo packages are predownloaded.
MirroredOriginSet repoOrigins() const
The repodata origins.
bool keepPackages() const
Whether packages downloaded from this repository will be kept in local cache.
Pathname path() const
Repository path.
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.