Go to the documentation of this file.
30 #undef ZYPP_BASE_LOGGER_LOGGROUP
31 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp:fetcher"
67 if ( lhs->location.medianr() == rhs->location.medianr() )
68 return lhs->location.filename() < rhs->location.filename();
70 return lhs->location.medianr() < rhs->location.medianr();
118 return str << obj->location;
136 Fetcher::Options
options()
const;
157 static shared_ptr<Impl> _nullimpl(
new Impl );
199 void validate(
const Pathname & localfile_r,
const std::list<FileChecker> & checkers_r );
205 const Pathname &dest_dir, FetcherJob::Flags flags );
220 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
223 {
return new Impl( *
this ); }
226 std::set<FetcherIndex_Ptr,SameFetcherIndex>
_indexes;
245 job.reset(
new FetcherJob(resource, deltafile));
268 job->checkers.push_back(checker);
273 _resources.push_back(job);
283 job->checkers.push_back(checker);
289 _resources.push_back(job);
295 if ( _mediaSetAccess )
296 _mediaSetAccess->precacheFiles( {resource} );
301 job->checkers.push_back(checker);
302 _resources.push_back(job);
307 MIL <<
"adding index " << resource << endl;
322 _mediaSetAccess = &media;
332 DBG <<
"Adding fetcher cache: '" << cache_dir <<
"'." << endl;
333 _caches.insert(cache_dir);
338 ERR <<
"Not adding cache: '" << cache_dir <<
"'. Not a directory." << endl;
343 ERR <<
"Not adding cache '" << cache_dir <<
"'. Path does not exists." << endl;
359 swap( ret, cacheLocation );
363 MIL <<
"start fetcher with " << _caches.size() <<
" cache directories." << endl;
364 for(
const Pathname & cacheDir : _caches )
366 cacheLocation = cacheDir / resource_r.
filename();
369 MIL <<
"file " << resource_r.
filename() <<
" found in cache " << cacheDir << endl;
370 swap( ret, cacheLocation );
382 MIL <<
"Checking job [" << localfile_r <<
"] (" << checkers_r.size() <<
" checkers )" << endl;
387 chkfnc( localfile_r );
389 ERR <<
"Invalid checker for '" << localfile_r <<
"'" << endl;
412 auto fnc_addIfInContent( [&](
const std::string & index_r ) ->
bool
421 downloadAndReadIndexList( media, dest_dir );
427 fnc_addIfInContent(
"CHECKSUMS" ) || fnc_addIfInContent(
"SHA1SUMS" );
431 fnc_addIfInContent(
"content" );
440 != _dircontent.end() )
444 std::copy(filled.begin(), filled.end(), std::back_inserter(content));
453 std::copy(tofill.begin(), tofill.end(), std::back_inserter(content));
460 const Pathname &dest_dir, FetcherJob::Flags flags )
464 MIL <<
"Adding directory " << resource.
filename() << endl;
467 getDirectoryContent(media, resource, content);
472 WAR <<
"Skiping subtree hidden at " << resource.
filename() << endl;
478 autoaddIndexes(content, media, resource, dest_dir);
480 for ( filesystem::DirContent::const_iterator it = content.begin();
496 if ( _checksums.find(filename.
asString()) != _checksums.end() )
499 chksm = _checksums[filename.
asString()];
503 WAR <<
"Resource " << filename <<
" has no checksum in the index either." << endl;
513 addDirJobs(media, filename, dest_dir, flags);
528 scoped_ptr<MediaSetAccess::ReleaseFileGuard> releaseFileGuard;
531 Pathname tmpFile = locateInCache( resource, destDir_r );
532 if ( tmpFile.
empty() )
534 MIL <<
"Not found in cache, retrieving..." << endl;
543 if ( tmpFile == destFullPath )
547 validate( tmpFile, jobp_r->checkers );
550 if ( tmpFile == destFullPath )
554 if (
assert_dir( destFullPath->dirname() ) != 0 )
566 WAR <<
"optional resource " << resource <<
" could not be transferred." << endl;
586 { _repoindex = data_r; }
595 readChecksumsIndex(index, basedir);
596 else if ( index.
basename() ==
"content" )
597 readContentFileIndex(index, basedir);
599 WAR << index <<
": index file format not known" << endl;
607 MIL << index <<
" contains " << reader.
_repoindex->mediaFileChecksums.size() <<
" checksums." << endl;
611 _checksums[(basedir + it->first).
asString()] = it->second;
618 std::ifstream in( index.
c_str() );
622 while (
getline( in, buffer ) )
625 if ( buffer[0] ==
'#' )
632 if ( buffer.empty() )
634 WAR <<
"Missing filename in CHECKSUMS file: " << index.
asString() <<
" (" <<
checksum <<
")" << endl;
647 MIL <<
"downloading index " << resource << endl;
673 fetcher.
start( dest_dir, media );
682 fetcher.
start( dest_dir, media );
689 WAR <<
"No public key specified by user for index '" << keyloc.
filename() <<
"'"<< endl;
693 fetcher.
start( dest_dir, media );
704 if ( _indexes.empty() )
706 MIL <<
"No indexes to read." << endl;
710 for_( it_idx, _indexes.begin(), _indexes.end() )
712 if ( (*it_idx)->read )
714 DBG <<
"Already read index " <<
PathInfo(dest_dir + (*it_idx)->location.filename()) << endl;
719 downloadIndex( media, (*it_idx)->location, dest_dir );
721 readIndex( dest_dir + (*it_idx)->location.filename(), (*it_idx)->location.filename().
dirname() );
723 MIL <<
"Remember read index " <<
PathInfo(dest_dir + (*it_idx)->location.filename()) << endl;
724 (*it_idx)->read =
true;
727 MIL <<
"done reading indexes" << endl;
733 if ( !_mediaSetAccess )
735 start( dest_dir, *_mediaSetAccess, progress );
744 _mediaSetAccess =
nullptr;
747 progress.
sendTo(progress_receiver);
749 downloadAndReadIndexList(media, dest_dir);
756 addDirJobs(media, location, dest_dir, jobp->flags);
770 getDirectoryContent(media, jobp->location.filename().dirname(), content);
773 MIL <<
"Autodiscovering signed indexes on '"
774 << jobp->location.filename().dirname() <<
"' for '"
775 << jobp->location.filename() <<
"'" << endl;
777 autoaddIndexes(content, media, jobp->location.filename().dirname(), dest_dir);
781 getDirectoryContent(media,
Pathname(
"/"), content);
784 MIL <<
"Autodiscovering signed indexes on '"
786 << jobp->location.filename() <<
"'" << endl;
788 autoaddIndexes(content, media,
Pathname(
"/"), dest_dir);
793 if ( jobp->location.checksum().empty() )
795 if ( _checksums.find(jobp->location.filename().asString())
796 != _checksums.end() )
798 CheckSum chksm = _checksums[jobp->location.filename().asString()];
800 jobp->checkers.push_back(digest_check);
810 jobp->checkers.push_back(digest_check);
818 jobp->checkers.push_back(digest_check);
823 provideToDest( media, dest_dir, jobp );
825 if ( ! progress.
incr() )
833 for ( std::list<FetcherJob_Ptr>::const_iterator it_res = obj.
_resources.begin(); it_res != obj.
_resources.end(); ++it_res )
Class to encapsulate the OnMediaLocation object and the FileChecker together.
friend std::ostream & operator<<(std::ostream &str, const Fetcher::Impl &obj)
Impl * clone() const
clone for RWCOW_pointer
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
OnMediaLocation location
Index localtion.
bool isExist() const
Return whether valid stat info exists.
void enqueueDigested(const OnMediaLocation &resource, const FileChecker &checker=FileChecker(), const Pathname &deltafile=Pathname())
Enqueue a object for transferal, they will not be transferred until start() is called.
Base class for Exception.
Pathname locateInCache(const OnMediaLocation &resource_r, const Pathname &destDir_r)
Tries to locate the file represented by job by looking at the cache (matching checksum is mandatory).
void addCachePath(const Pathname &cache_dir)
adds a directory to the list of directories where to look for cached files
DefaultIntegral< bool, false > read
Whether we read this index.
void enqueueDigestedDir(const OnMediaLocation &resource, bool recursive, const FileChecker &checker=FileChecker())
shared_ptr< FetcherJob > FetcherJob_Ptr
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
void addCachePath(const Pathname &cache_dir)
void provideToDest(MediaSetAccess &media_r, const Pathname &destDir_r, const FetcherJob_Ptr &jobp_r)
Provide the resource to dest_dir.
Checks for the validity of a signature.
FetcherIndex(const OnMediaLocation &loc)
std::set ordering (less semantic)
Parse repoindex part from a content file.
void enqueue(const OnMediaLocation &resource, const FileChecker &checker=FileChecker())
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...
int unlink(const Pathname &path)
Like 'unlink'.
void setOptions(Options options)
Set the Fetcher options.
bool operator()(const FetcherIndex_Ptr &lhs, const FetcherIndex_Ptr &rhs) const
Options options() const
Get current options.
std::string getline(std::istream &str)
Read one line from stream.
Listentry returned by readdir.
std::set< FetcherIndex_Ptr, SameFetcherIndex > _indexes
void enqueueDir(const OnMediaLocation &resource, bool recursive=false, const FileChecker &checker=FileChecker())
Enqueue a directory.
void setMediaSetAccess(MediaSetAccess &media)
static shared_ptr< Impl > nullimpl()
Offer default Impl.
@ AutoAddChecksumsIndexes
If a CHECKSUMS file is found, it is downloaded and read.
void remember(const Exception &old_r)
Store an other Exception as history.
Wrapper class for ::stat/::lstat.
ZYPP_DECLARE_FLAGS(Flags, Flag)
void addIndex(const OnMediaLocation &resource)
Adds an index containing metadata (for example checksums ) that will be retrieved and read before the...
std::list< FileChecker > checkers
const char * c_str() const
String representation.
void readIndex(const Pathname &index, const Pathname &basedir)
reads a downloaded index file and updates internal attributes table
void consumeIndex(const parser::susetags::RepoIndex_Ptr &data_r)
void enqueueDir(const OnMediaLocation &resource, bool recursive, const FileChecker &checker=FileChecker())
Fetcher::Options _options
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(DiskUsageCounter::MountPoint::HintFlags)
MediaSetAccess * _mediaSetAccess
void downloadIndex(MediaSetAccess &media, const OnMediaLocation &resource, const Pathname &dest_dir)
download the indexes and reads them
Easy-to use interface to the ZYPP dependency resolver.
std::list< DirEntry > DirContent
Returned by readdir.
std::list< FetcherJob_Ptr > _resources
std::string stripFirstWord(std::string &line, const bool ltrim_first)
std::map< std::string, filesystem::DirContent > _dircontent
void enqueueDigestedDir(const OnMediaLocation &resource, bool recursive=false, const FileChecker &checker=FileChecker())
Enqueue a directory and always check for checksums.
Fetcher::Options options() const
bool is_checksum(const Pathname &file, const CheckSum &checksum)
check files checksum
void getDirectoryContent(MediaSetAccess &media, const OnMediaLocation &resource, filesystem::DirContent &content)
reads the content of a directory but keeps a cache
void downloadAndReadIndexList(MediaSetAccess &media, const Pathname &dest_dir)
download the indexes and reads them
void setOptions(Fetcher::Options options)
shared_ptr< FetcherIndex > FetcherIndex_Ptr
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
void enqueueDigested(const OnMediaLocation &resource, const FileChecker &checker=FileChecker(), const Pathname &deltafile=Pathname())
void start(const Pathname &dest_dir, const ProgressData::ReceiverFnc &progress)
void setMediaSetAccess(MediaSetAccess &media)
Sets the media set access that will be used to precache and to download the files when start is calle...
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
parser::susetags::RepoIndex_Ptr _repoindex
void validate(const Pathname &localfile_r, const std::list< FileChecker > &checkers_r)
Validates the provided file against its checkers.
void readChecksumsIndex(const Pathname &index, const Pathname &basedir)
specific version of readIndex for CHECKSUMS file
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Pathname dirname() const
Return all but the last component od this path.
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
void reset()
Reset the transfer (jobs) list.
class that represents indexes which add metadata to fetcher jobs and therefore need to be retrieved i...
std::ostream & copy(std::istream &from_r, std::ostream &to_r)
Copy istream to ostream.
bool empty() const
Test for an empty path.
FetcherJob(const OnMediaLocation &loc, const Pathname dfile=Pathname())
@ AutoAddContentFileIndexes
If a content file is found, it is downloaded and read.
function< void(const Pathname &file)> FileChecker
Functor signature used to check files.
void enqueue(const OnMediaLocation &resource, const FileChecker &checker=FileChecker())
Enqueue a object for transferal, they will not be transferred until start() is called.
std::set< Pathname > _caches
std::string basename() const
Return the last component of this path.
std::map< std::string, CheckSum > _checksums
String related utilities and Regular expression matching.
void resetDispose()
Set no dispose function.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
const std::string & asString() const
String representation.
virtual void parse(const InputStream &imput_r, const ProgressData::ReceiverFnc &fnc_r=ProgressData::ReceiverFnc())
Parse the stream.
void addDirJobs(MediaSetAccess &media, const OnMediaLocation &resource, const Pathname &dest_dir, FetcherJob::Flags flags)
scan the directory and adds the individual jobs
std::ostream & operator<<(std::ostream &str, const Fetcher::Impl &obj)
Stream output.
void readContentFileIndex(const Pathname &index, const Pathname &basedir)
specific version of readIndex for content file
void autoaddIndexes(const filesystem::DirContent &content, MediaSetAccess &media, const OnMediaLocation &resource, const Pathname &dest_dir)
auto discovery and reading of indexes
Maintain [min,max] and counter (value) for progress counting.
void addIndex(const OnMediaLocation &resource)
This class allows to retrieve a group of files in a confortable way, providing some smartness that do...
bool incr(value_type val_r=1)
Increment counter value (default by 1).