{
filesystem::TmpDir dest;
- fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir"), true);
+ fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
fetcher.reset();
}
// add the key as trusted
getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
- fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir"), true);
+ fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
fetcher.start( dest.path(), media );
BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2").isExist() );
BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
-
+
fetcher.reset();
}
// add the key as trusted
getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
- fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir-broken"), true);
- BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
+ fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
+ BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
fetcher.reset();
}
- {
+ {
filesystem::TmpDir dest;
- fetcher.enqueue(OnMediaLocation().setFilename("/file-1.txt"));
- fetcher.start( dest.path(), media );
+ fetcher.enqueue(OnMediaLocation("/file-1.txt"));
+ fetcher.start( dest.path(), media );
BOOST_CHECK( PathInfo(dest.path() + "/file-1.txt").isExist() );
}
-
+
//MIL << fetcher;
}
Fetcher fetcher;
filesystem::TmpDir dest;
- fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir"), true);
+ fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
fetcher.start( dest.path(), media );
fetcher.reset();
- fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir-broken"), true);
- BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
+ fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
+ BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
fetcher.reset();
*/
struct FetcherJob
{
-
+
FetcherJob( const OnMediaLocation &loc )
: location(loc)
, directory(false)
//CompositeFileChecker checkers;
list<FileChecker> checkers;
bool directory;
- bool recursive;
+ bool recursive;
};
typedef shared_ptr<FetcherJob> FetcherJob_Ptr;
~Impl() {
MIL << endl;
}
-
+
void enqueue( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() );
void enqueueDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker = FileChecker() );
void enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() );
* \throws Exception
*/
void validate( const OnMediaLocation &resource, const Pathname &dest_dir, const list<FileChecker> &checkers );
-
+
/**
* scan the directory and adds the individual jobs
*/
job->checkers.push_back(checker);
_resources.push_back(job);
}
-
- void Fetcher::Impl::enqueueDir( const OnMediaLocation &resource,
+
+ void Fetcher::Impl::enqueueDir( const OnMediaLocation &resource,
bool recursive,
const FileChecker &checker )
{
job->directory = true;
job->recursive = recursive;
_resources.push_back(job);
- }
+ }
void Fetcher::Impl::enqueue( const OnMediaLocation &resource, const FileChecker &checker )
{
{
ERR << "Not adding cache '" << cache_dir << "'. Path does not exists." << endl;
}
-
+
}
bool Fetcher::Impl::provideFromCache( const OnMediaLocation &resource, const Pathname &dest_dir )
{
Pathname dest_full_path = dest_dir + resource.filename();
-
+
// first check in the destination directory
if ( PathInfo(dest_full_path).isExist() )
{
&& (! resource.checksum().empty() ) )
return true;
}
-
+
MIL << "start fetcher with " << _caches.size() << " cache directories." << endl;
for_ ( it_cache, _caches.begin(), _caches.end() )
{
} // iterate over caches
return false;
}
-
+
void Fetcher::Impl::validate( const OnMediaLocation &resource, const Pathname &dest_dir, const list<FileChecker> &checkers )
{
// no matter where did we got the file, try to validate it:
ERR << "Invalid checker for '" << localfile << "'" << endl;
}
}
-
+
}
catch ( const FileCheckException &e )
{
}
void Fetcher::Impl::addDirJobs( MediaSetAccess &media,
- const OnMediaLocation &resource,
+ const OnMediaLocation &resource,
const Pathname &dest_dir, bool recursive )
{
// first get the content of the directory so we can add
MIL << "Adding directory " << resource.filename() << endl;
filesystem::DirContent content;
media.dirInfo( content, resource.filename(), false /* dots */, resource.medianr());
-
+
filesystem::DirEntry shafile, shasig, shakey;
shafile.name = "SHA1SUMS"; shafile.type = filesystem::FT_FILE;
shasig.name = "SHA1SUMS.asc"; shasig.type = filesystem::FT_FILE;
shakey.name = "SHA1SUMS.key"; shakey.type = filesystem::FT_FILE;
-
+
// create a new fetcher with a different state to transfer the
// file containing checksums and its signature
Fetcher fetcher;
SignatureFileChecker sigchecker;
// now try to find the SHA1SUMS signature
- if ( find(content.begin(), content.end(), shasig)
+ if ( find(content.begin(), content.end(), shasig)
!= content.end() )
{
MIL << "found checksums signature file: " << shasig.name << endl;
MIL << "no signature for " << shafile.name << endl;
// look for the SHA1SUMS.key file
- if ( find(content.begin(), content.end(), shakey)
+ if ( find(content.begin(), content.end(), shakey)
!= content.end() )
{
MIL << "found public key file: " << shakey.name << endl;
}
// look for the SHA1SUMS public key file
- if ( find(content.begin(), content.end(), shafile)
+ if ( find(content.begin(), content.end(), shafile)
!= content.end() )
{
MIL << "found checksums file: " << shafile.name << endl;
fetcher.enqueue( OnMediaLocation(resource.filename() + shafile.name, resource.medianr()).setOptional(true) );
- assert_dir(dest_dir + resource.filename());
+ assert_dir(dest_dir + resource.filename());
fetcher.start( dest_dir, media );
fetcher.reset();
}
// hash table to store checksums
map<string, CheckSum> checksums;
-
+
// look for the SHA1SUMS file
if ( find(content.begin(), content.end(), shafile) != content.end() )
{
std::ifstream in( pShafile.c_str() );
string buffer;
if ( ! in.fail() )
- {
+ {
while ( getline(in, buffer) )
{
vector<string> words;
// skip SHA1SUMS* as they were already retrieved
if ( str::hasPrefix(it->name, "SHA1SUMS") )
continue;
-
+
Pathname filename = resource.filename() + it->name;
-
+
switch ( it->type )
{
case filesystem::FT_NOT_AVAIL: // old directory.yast contains no typeinfo at all
CheckSum checksum;
if ( checksums.find(it->name) != checksums.end() )
checksum = checksums[it->name];
-
+
// create a resource from the file
// if checksum was not available we will have a empty
// checksum, which will end in a validation anyway
// warning the user that there is no checksum
- enqueueDigested(OnMediaLocation()
- .setFilename(filename)
+ enqueueDigested(OnMediaLocation(filename, resource.medianr())
.setChecksum(checksum));
-
+
break;
}
case filesystem::FT_DIR: // newer directory.yast contain at least directory info
void Fetcher::Impl::provideToDest( MediaSetAccess &media, const OnMediaLocation &resource, const Pathname &dest_dir )
{
bool got_from_cache = false;
-
+
// start look in cache
got_from_cache = provideFromCache(resource, dest_dir);
-
+
if ( ! got_from_cache )
{
MIL << "Not found in cache, downloading" << endl;
-
+
// try to get the file from the net
try
{
// continue with next file
return;
}
- }
+ }
void Fetcher::Impl::start( const Pathname &dest_dir,
MediaSetAccess &media,
progress.sendTo(progress_receiver);
for ( list<FetcherJob_Ptr>::const_iterator it_res = _resources.begin(); it_res != _resources.end(); ++it_res )
- {
+ {
if ( (*it_res)->directory )
{
// validate job, this throws if not valid
validate((*it_res)->location, dest_dir, (*it_res)->checkers);
-
+
if ( ! progress.incr() )
ZYPP_THROW(AbortRequestException());
} // for each job
inline std::ostream & operator<<( std::ostream & str, const Fetcher::Impl & obj )
{
for ( list<FetcherJob_Ptr>::const_iterator it_res = obj._resources.begin(); it_res != obj._resources.end(); ++it_res )
- {
+ {
str << *it_res;
}
return str;
/**
* media number where the resource is located.
* for a url cd:// this could be 1..N.
- * for a url of type http://host/path/CD1, a media number 2
+ * for a url of type http://host/path/CD1, a media number 2
* means looking on http://host/path/CD1/../CD2
*/
unsigned medianr() const { return _medianr; }
OnMediaLocation & setOpenChecksum( const CheckSum & val_r )
{ _openchecksum = val_r; return *this; }
- /**
+ /**
* Set the wether the resource is optional or not
* \see optional
*/
{ _optional = val; return *this; }
public:
- /**
- * Individual manipulation of \c medianr.
- * Using \ref setLocation is prefered.
+ /**
+ * Individual manipulation of \c medianr (prefer \ref setLocation).
+ * Using \ref setLocation is prefered as us usually have to adjust
+ * \c filename and \c medianr in sync.
*/
- OnMediaLocation & setMedianr( unsigned val_r )
+ OnMediaLocation & changeMedianr( unsigned val_r )
{ _medianr = val_r; return *this; }
/**
- * Individual manipulation of \c medianr.
- * Use \ref setMediaNr instead
- */
- ZYPP_DEPRECATED OnMediaLocation & changeMedianr( unsigned val_r )
- { return setMedianr(val_r); }
-
- /**
- * Individual manipulation of \c filename.
- * Using \ref setLocation is prefered.
+ * Individual manipulation of \c filename (prefer \ref setLocation).
+ * Using \ref setLocation is preferedas us usually have to adjust
+ * \c filename and \c medianr in sync.
*/
- OnMediaLocation &setFilename( const Pathname & val_r )
+ OnMediaLocation & changeFilename( const Pathname & val_r )
{ _filename = val_r; return *this; }
- /**
- * Individual manipulation of \c filename.
- * Use \ref setFilename instead.
- */
- ZYPP_DEPRECATED OnMediaLocation & changeFilename( const Pathname & val_r )
- { return setFilename(val_r); }
-
private:
unsigned _medianr;
Pathname _filename;