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()),
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 );
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 );
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;
165 it =
_medias.find( urls.front() );
166 shared_ptr<MediaSetAccess> media;
185 media->setLabel( repo.
name() );
194 std::map<shared_ptr<MediaSetAccess>,
RepoInfo>::const_iterator it;
198 if ( it->second.alias() == repo.
alias() )
207 DBG <<
"Verifier for repo '" << repo.
alias() <<
"':" << lverifier << endl;
215 WAR <<
"Invalid verifier for repo '" << repo.
alias() <<
"' in '" << repo.
metadataPath() <<
"': " << lverifier << endl;
220 DBG <<
"No media verifier for repo '" << repo.
alias() <<
"' media.1/media does not exist in '" << repo.
metadataPath() <<
"'" << endl;
225 WAR <<
"'" << repo.
alias() <<
"' metadata path is empty. Can't set verifier. Probably this repository does not come from RepoManager." << endl;
231 std::map<Url, shared_ptr<MediaSetAccess> >
_medias;
240 : _impl( new
Impl(
std::move(defaultPolicy_r) ) )
258 MIL << locWithPath << endl;
265 str::form(
_(
"Can't provide file '%s' from repository '%s'"),
267 repo_r.
alias().c_str() ) );
287 if ( ! pi.isExist() )
293 if ( geteuid() != 0 && ! pi.userMayW() )
295 WAR <<
"Destination dir '" << destinationDir <<
"' is not user writable, using tmp space." << endl;
296 destinationDir = getZYpp()->tmpPath() / destinationDir;
299 MIL <<
"Added cache path " << destinationDir << endl;
306 for (
auto it = groupedBaseUrls.begin(); it != groupedBaseUrls.end();
310 std::vector<Url> urls( *it );
313 if ( urls.empty () ) {
314 MIL <<
"Skipping empty Url group" << std::endl;
320 MIL <<
"Providing file of repo '" << repo_r.
alias() <<
"' from: ";
321 std::for_each( urls.begin (), urls.end(), [&](
const zypp::Url &u ){
331 fetcher.
start( destinationDir, *access );
340 MIL <<
"provideFile at " << ret << endl;
357 WAR <<
"Trying next url" << endl;
bool effectiveBaseUrlsEmpty() const
whether effective repository urls are available
Pathname path() const
Repository path.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
bool progress(int value) const
Evaluate callback.
const char * c_str() const
String representation.
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
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
void remember(const Exception &old_r)
Store an other Exception as history.
Policy for provideFile and RepoMediaAccess.
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...
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
bool empty() const
Test for an empty path.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
url_set effectiveBaseUrls() const
The complete set of effective repository urls.
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.
std::string alias() const
unique identifier for this source.
bool isExist() const
Return whether valid stat info exists.
ProvideFilePolicy & fileChecker(FileChecker fileChecker_r)
Add a FileCecker passed down to the Fetcher.
std::vector< std::vector< Url > > groupedBaseUrls() const
Returns the currently known effective baseUrls in groups, where each group contains a primary base ur...
Pathname metadataPath() const
Path where this repo metadata was read from.
int unlink(const Pathname &path)
Like 'unlink'.
Pathname predownloadPath() const
Path where this repo packages are predownloaded.
#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.
std::string name() const
Repository name.
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...
Pathname packagesPath() const
Path where this repo packages are cached.
Wrapper class for ::stat/::lstat.
Base for exceptions caused by explicit user request.
void enqueue(const OnMediaLocation &resource, const FileChecker &checker=FileChecker())
Enqueue a object for transferal, they will not be transferred until start() is called.
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...