1
/*---------------------------------------------------------------------\
3
| |__ / \ / / . \ . \ |
8
\---------------------------------------------------------------------*/
9
/** \file zypp/target/CommitPackageCacheReadAhead.cc
14
#include "zypp/base/Logger.h"
15
#include "zypp/base/Exception.h"
16
#include "zypp/PathInfo.h"
17
#include "zypp/RepoInfo.h"
18
#include "zypp/Package.h"
19
#include "zypp/target/CommitPackageCacheReadAhead.h"
23
///////////////////////////////////////////////////////////////////
25
{ /////////////////////////////////////////////////////////////////
26
///////////////////////////////////////////////////////////////////
28
{ /////////////////////////////////////////////////////////////////
30
///////////////////////////////////////////////////////////////////
32
// CLASS NAME : IMediaKey
34
///////////////////////////////////////////////////////////////////
36
std::ostream & operator<<( std::ostream & str, const IMediaKey & obj )
38
return str << "[S" << obj._repo.id() << ":" << obj._mediaNr << "]"
39
<< " " << obj._repo.info().alias();
42
///////////////////////////////////////////////////////////////////
44
// CLASS NAME : CommitPackageCacheReadAhead
46
///////////////////////////////////////////////////////////////////
48
///////////////////////////////////////////////////////////////////
50
// METHOD NAME : CommitPackageCacheReadAhead::CommitPackageCacheReadAhead
53
CommitPackageCacheReadAhead::CommitPackageCacheReadAhead( const Pathname & /*rootDir_r*/,
54
const PackageProvider & packageProvider_r )
55
: CommitPackageCache::Impl( packageProvider_r )
56
//, _rootDir( rootDir_r )
59
///////////////////////////////////////////////////////////////////
61
// METHOD NAME : CommitPackageCacheReadAhead::onInteractiveMedia
64
bool CommitPackageCacheReadAhead::onInteractiveMedia( const PoolItem & pi ) const
66
if ( pi->mediaNr() == 0 ) // no media access at all
68
if ( pi->repoInfo().baseUrlsEmpty() )
69
return false; // no Url - should actually not happen
70
std::string scheme( pi->repoInfo().baseUrlsBegin()->getScheme() );
71
return ( scheme == "dvd" || scheme == "cd" );
74
///////////////////////////////////////////////////////////////////
76
// METHOD NAME : CommitPackageCacheReadAhead::cacheLastInteractive
79
void CommitPackageCacheReadAhead::cacheLastInteractive( const PoolItem & citem_r )
81
// Fill cache errors are never proagated.
84
doCacheLastInteractive( citem_r );
86
catch ( const Exception & excpt_r )
88
ZYPP_CAUGHT( excpt_r );
89
WAR << "Failed to cache " << _lastInteractive << endl;
93
///////////////////////////////////////////////////////////////////
95
// METHOD NAME : CommitPackageCacheReadAhead::doCacheLastInteractive
98
void CommitPackageCacheReadAhead::doCacheLastInteractive( const PoolItem & citem_r )
100
unsigned addToCache = 0;
101
bool sawCitem = false;
103
// Collect all remaining packages to install from
104
// _lastInteractive media. (just the PoolItem data)
105
for_( it, commitList().begin(), commitList().end() )
114
if ( IMediaKey( pi ) == _lastInteractive
115
&& pi.status().isToBeInstalled()
116
&& isKind<Package>(pi.resolvable()) )
118
if ( ! pi->asKind<Package>()->isCached() )
120
ManagedFile fromSource( sourceProvidePackage( pi ) );
121
if ( fromSource->empty() )
123
ERR << "Copy to cache failed on " << fromSource << endl;
124
ZYPP_THROW( Exception("Copy to cache failed.") );
126
fromSource.resetDispose(); // keep the package file in the cache
133
MIL << "Cached " << _lastInteractive << ": " << addToCache << " items." << endl;
136
///////////////////////////////////////////////////////////////////
138
// METHOD NAME : CommitPackageCacheReadAhead::get
139
// METHOD TYPE : ManagedFile
141
ManagedFile CommitPackageCacheReadAhead::get( const PoolItem & citem_r )
143
// Non CD/DVD media provide their packages without cache.
144
if ( ! onInteractiveMedia( citem_r ) )
146
return sourceProvidePackage( citem_r );
149
// Check whether it's cached.
150
ManagedFile ret( sourceProvideCachedPackage( citem_r ) );
151
if ( ! ret->empty() )
154
IMediaKey current( citem_r );
155
if ( current != _lastInteractive )
157
if ( _lastInteractive != IMediaKey() )
159
cacheLastInteractive( citem_r );
162
DBG << "Interactive change [" << ++_dbgChanges << "] from " << _lastInteractive << " to " << current << endl;
163
_lastInteractive = current;
166
// Provide and return the file from media.
167
return sourceProvidePackage( citem_r );
171
/////////////////////////////////////////////////////////////////
172
} // namespace target
173
///////////////////////////////////////////////////////////////////
174
/////////////////////////////////////////////////////////////////
176
///////////////////////////////////////////////////////////////////